From 3c9d94376b398798e3c408620e2ded51f5da4846 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 12:02:35 +0000 Subject: [PATCH 01/82] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b56b0d..adc9748 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var MultiSlice = require( '@stdlib/slice-multi' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -119,7 +119,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -127,11 +127,11 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; } diff --git a/package.json b/package.json index 969f277..9d800f1 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-numel": "^0.1.0", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/symbol-iterator": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" From 07b841d587af5fa0d680cb73adbbe059ca24f672 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 16:32:52 +0000 Subject: [PATCH 02/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 243 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 594 -- test/test.js | 594 -- 41 files changed, 6207 insertions(+), 5075 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -219,7 +212,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -281,9 +274,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdcc55d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(n,r){return function(){return r||n((r={exports:{}}).exports,r),r.exports}};var b=j(function(G,w){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),E=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),P=require('@stdlib/assert-has-own-property/dist'),c=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),k=require('@stdlib/ndarray-base-numel/dist'),L=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/slice-multi/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function z(n,r,a){var e,i;for(e=n-3;e>=0&&(i=(a[e]+1)%r[e],a[e]=i,!(i>0));e--);return a}function g(n){var r,a,e,i,u,v,t,o,y,s,m;if(!F(n))throw new TypeError(p('null4f',n));if(i={writable:!1},arguments.length>1){if(r=arguments[1],!E(r))throw new TypeError(p('null2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(p('null2o',"readonly",r.readonly));i.writable=!r.readonly}}if(a=n.shape,e=a.length,e<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=k(a),s===0&&(v=!0),s/=a[e-2],o=e-1,y=a[o],m=-1,t=S(e),t[e-2]=null,u={},f(u,"next",q),f(u,"return",h),c&&f(u,c,O),u;function q(){var l,d;return m+=1,v||m>=s?{done:!0}:(l=V.apply(null,t),d=(t[o]+1)%y,t[o]=d,d===0&&z(e,a,t),{value:L(n,l,!0,i.writable),done:!1})}function h(l){return v=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return g(n,i)}}w.exports=g -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d82f912..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar MultiSlice = require( '@stdlib/slice-multi' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Increments stack indices.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {NonNegativeIntegerArray} idx - current indices\n* @returns {NonNegativeIntegerArray} updated indices\n*/\nfunction incrementIndices( ndims, shape, idx ) {\n\tvar i;\n\tvar j;\n\n\t// Search for the first dimension in which we don't have to \"carry the one\"...\n\tfor ( i = ndims-3; i >= 0; i-- ) {\n\t\tj = ( idx[ i ] + 1 ) % shape[ i ];\n\t\tidx[ i ] = j;\n\n\t\t// If the current index value is greater than zero, we can continue iterating within the current sub-array...\n\t\tif ( j > 0 ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t}\n\t}\n\t// Retrieve the input array shape:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tincrementIndices( ndims, shape, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAS,QAAS,uBAAwB,EAc9C,SAASC,EAAkBC,EAAOC,EAAOC,EAAM,CAC9C,IAAIC,EACAC,EAGJ,IAAMD,EAAIH,EAAM,EAAGG,GAAK,IACvBC,GAAMF,EAAKC,CAAE,EAAI,GAAMF,EAAOE,CAAE,EAChCD,EAAKC,CAAE,EAAIC,EAGN,EAAAA,EAAI,IALiBD,IAK1B,CAID,OAAOD,CACR,CA8CA,SAASG,EAAeC,EAAI,CAC3B,IAAIC,EACAN,EACAD,EACAQ,EACAC,EACAC,EACAR,EACAS,EACAC,EACAC,EACAV,EAEJ,GAAK,CAACZ,EAAee,CAAE,EACtB,MAAM,IAAI,UAAWR,EAAQ,oEAAqEQ,CAAE,CAAE,EAKvG,GAHAE,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAD,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWT,EAAQ,qEAAsES,CAAQ,CAAE,EAE9G,GAAKf,EAAYe,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWT,EAAQ,+DAAgE,WAAYS,EAAQ,QAAS,CAAE,EAE7HC,EAAK,SAAW,CAACD,EAAQ,QAC1B,CACD,CAMA,GAJAN,EAAQK,EAAE,MACVN,EAAQC,EAAM,OAGTD,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAa,EAAIlB,EAAOM,CAAM,EACZY,IAAM,IACVH,EAAM,IAGPG,GAAKZ,EAAOD,EAAM,CAAE,EACpBW,EAAMX,EAAQ,EACdY,EAAKX,EAAOU,CAAI,EAGhBR,EAAI,GAGJD,EAAMR,EAAOM,CAAM,EAGnBE,EAAKF,EAAM,CAAE,EAAI,KAGjBS,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQK,CAAK,EAChC1B,EAAaqB,EAAM,SAAUM,CAAI,EAG5BtB,GACJL,EAAaqB,EAAMhB,EAAgBuB,CAAQ,EAErCP,EAQP,SAASK,GAAO,CACf,IAAIG,EACAb,EAEJ,OADAD,GAAK,EACAO,GAAOP,GAAKU,EACT,CACN,KAAQ,EACT,GAGDI,EAAIpB,EAAW,MAAO,KAAMK,CAAI,EAGhCE,GAAMF,EAAKS,CAAI,EAAI,GAAMC,EACzBV,EAAKS,CAAI,EAAIP,EACRA,IAAM,GAEVL,EAAkBC,EAAOC,EAAOC,CAAI,EAG9B,CACN,MAASN,EAAOU,EAAGW,EAAG,GAAMT,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASO,EAAKG,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOX,EAAeC,EAAGE,CAAK,CAC/B,CACD,CAKArB,EAAO,QAAUkB,ICxLjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "numel", "slice", "MultiSlice", "format", "incrementIndices", "ndims", "shape", "idx", "i", "j", "nditerColumns", "x", "options", "opts", "iter", "FLG", "dim", "S0", "N", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 7717763..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0b52073..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 f1b0bd3..3edb121 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0e95c33 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function p(e,r,t){var s,n;for(s=e-3;s>=0&&(n=(t[s]+1)%r[s],t[s]=n,!(n>0));s--);return t}function j(h){var v,f,u,b,c,y,g,w,x,E,T;if(!s(h))throw new TypeError(a("null4f,Pc",h));if(b={writable:!1},arguments.length>1){if(!r(v=arguments[1]))throw new TypeError(a("null2V,FD",v));if(n(v,"readonly")){if(!t(v.readonly))throw new TypeError(a("null2o,GE","readonly",v.readonly));b.writable=!v.readonly}}if(f=h.shape,(u=f.length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(E=d(f))&&(y=!0),E/=f[u-2],x=f[w=u-1],T=-1,(g=o(u))[u-2]=null,e(c={},"next",F),e(c,"return",k),i&&e(c,i,z),c;function F(){var e,r;return T+=1,y||T>=E?{done:!0}:(e=m.apply(null,g),r=(g[w]+1)%x,g[w]=r,0===r&&p(u,f,g),{value:l(h,e,!0,b.writable),done:!1})}function k(e){return y=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return j(h,b)}}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f350ffd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Increments stack indices.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {NonNegativeIntegerArray} idx - current indices\n* @returns {NonNegativeIntegerArray} updated indices\n*/\nfunction incrementIndices( ndims, shape, idx ) {\n\tvar i;\n\tvar j;\n\n\t// Search for the first dimension in which we don't have to \"carry the one\"...\n\tfor ( i = ndims-3; i >= 0; i-- ) {\n\t\tj = ( idx[ i ] + 1 ) % shape[ i ];\n\t\tidx[ i ] = j;\n\n\t\t// If the current index value is greater than zero, we can continue iterating within the current sub-array...\n\t\tif ( j > 0 ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t}\n\t}\n\t// Retrieve the input array shape:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tincrementIndices( ndims, shape, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["incrementIndices","ndims","shape","idx","i","j","nditerColumns","x","options","opts","iter","FLG","dim","S0","N","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","done","MultiSlice","apply","value","slice"],"mappings":";;6iCA8CA,SAASA,EAAkBC,EAAOC,EAAOC,GACxC,IAAIC,EACAC,EAGJ,IAAMD,EAAIH,EAAM,EAAGG,GAAK,IACvBC,GAAMF,EAAKC,GAAM,GAAMF,EAAOE,GAC9BD,EAAKC,GAAMC,IAGNA,EAAI,IALiBD,KAS3B,OAAOD,CACR,CA8CA,SAASG,EAAeC,GACvB,IAAIC,EACAN,EACAD,EACAQ,EACAC,EACAC,EACAR,EACAS,EACAC,EACAC,EACAV,EAEJ,IAAMW,EAAeR,GACpB,MAAM,IAAIS,UAAWC,EAAQ,YAAaV,IAK3C,GAHAE,EAAO,CACNS,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNb,EAAUW,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaT,IAE3C,GAAKc,EAAYd,EAAS,YAAe,CACxC,IAAMe,EAAWf,EAAQgB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYT,EAAQgB,WAE/Df,EAAKS,UAAYV,EAAQgB,QACzB,CACD,CAMD,GAJAtB,EAAQK,EAAEL,OACVD,EAAQC,EAAMkB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXF,EAAIW,EAAOvB,MAEVS,GAAM,GAGPG,GAAKZ,EAAOD,EAAM,GAElBY,EAAKX,EADLU,EAAMX,EAAQ,GAIdG,GAAK,GAGLD,EAAMuB,EAAOzB,IAGRA,EAAM,GAAM,KAIjB0B,EADAjB,EAAO,CAAA,EACY,OAAQkB,GAC3BD,EAAajB,EAAM,SAAUmB,GAGxBC,GACJH,EAAajB,EAAMoB,EAAgBC,GAE7BrB,EAQP,SAASkB,IACR,IAAII,EACA3B,EAEJ,OADAD,GAAK,EACAO,GAAOP,GAAKU,EACT,CACNmB,MAAQ,IAIVD,EAAIE,EAAWC,MAAO,KAAMhC,GAG5BE,GAAMF,EAAKS,GAAQ,GAAMC,EACzBV,EAAKS,GAAQP,EACF,IAANA,GAEJL,EAAkBC,EAAOC,EAAOC,GAG1B,CACNiC,MAASC,EAAO9B,EAAGyB,GAAG,EAAMvB,EAAKS,UACjCe,MAAQ,GAET,CASD,SAASJ,EAAKO,GAEb,OADAzB,GAAM,EACDQ,UAAUC,OACP,CACNgB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASF,IACR,OAAOzB,EAAeC,EAAGE,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 adc9748..0000000 --- a/lib/main.js +++ /dev/null @@ -1,243 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Increments stack indices. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {NonNegativeIntegerArray} shape - array shape -* @param {NonNegativeIntegerArray} idx - current indices -* @returns {NonNegativeIntegerArray} updated indices -*/ -function incrementIndices( ndims, shape, idx ) { - var i; - var j; - - // Search for the first dimension in which we don't have to "carry the one"... - for ( i = ndims-3; i >= 0; i-- ) { - j = ( idx[ i ] + 1 ) % shape[ i ]; - idx[ i ] = j; - - // If the current index value is greater than zero, we can continue iterating within the current sub-array... - if ( j > 0 ) { - break; - } - } - return idx; -} - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - } - } - // Retrieve the input array shape: - shape = x.shape; - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = MultiSlice.apply( null, idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - incrementIndices( ndims, shape, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 9d800f1..80882ba 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/symbol-iterator": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-slice": "github:stdlib-js/ndarray-slice#main", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..133b323 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index f71f253..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,594 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5bb8a39..0000000 --- a/test/test.js +++ /dev/null @@ -1,594 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 508bf6571242ae0a627f1475e20eb580367aef60 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 11:49:55 +0000 Subject: [PATCH 03/82] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b56b0d..adc9748 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var MultiSlice = require( '@stdlib/slice-multi' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -119,7 +119,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -127,11 +127,11 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; } diff --git a/package.json b/package.json index 6e4f75a..b6e02ba 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 5b97acf0c794c15c358ad84deb5ad2a32af3fd53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 17:38:28 +0000 Subject: [PATCH 04/82] Remove files --- index.d.ts | 83 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6265 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 3edb121..0000000 --- a/index.d.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } 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). - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( src: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0e95c33..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function p(e,r,t){var s,n;for(s=e-3;s>=0&&(n=(t[s]+1)%r[s],t[s]=n,!(n>0));s--);return t}function j(h){var v,f,u,b,c,y,g,w,x,E,T;if(!s(h))throw new TypeError(a("null4f,Pc",h));if(b={writable:!1},arguments.length>1){if(!r(v=arguments[1]))throw new TypeError(a("null2V,FD",v));if(n(v,"readonly")){if(!t(v.readonly))throw new TypeError(a("null2o,GE","readonly",v.readonly));b.writable=!v.readonly}}if(f=h.shape,(u=f.length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(E=d(f))&&(y=!0),E/=f[u-2],x=f[w=u-1],T=-1,(g=o(u))[u-2]=null,e(c={},"next",F),e(c,"return",k),i&&e(c,i,z),c;function F(){var e,r;return T+=1,y||T>=E?{done:!0}:(e=m.apply(null,g),r=(g[w]+1)%x,g[w]=r,0===r&&p(u,f,g),{value:l(h,e,!0,b.writable),done:!1})}function k(e){return y=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return j(h,b)}}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f350ffd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Increments stack indices.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {NonNegativeIntegerArray} idx - current indices\n* @returns {NonNegativeIntegerArray} updated indices\n*/\nfunction incrementIndices( ndims, shape, idx ) {\n\tvar i;\n\tvar j;\n\n\t// Search for the first dimension in which we don't have to \"carry the one\"...\n\tfor ( i = ndims-3; i >= 0; i-- ) {\n\t\tj = ( idx[ i ] + 1 ) % shape[ i ];\n\t\tidx[ i ] = j;\n\n\t\t// If the current index value is greater than zero, we can continue iterating within the current sub-array...\n\t\tif ( j > 0 ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t}\n\t}\n\t// Retrieve the input array shape:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tincrementIndices( ndims, shape, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["incrementIndices","ndims","shape","idx","i","j","nditerColumns","x","options","opts","iter","FLG","dim","S0","N","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","done","MultiSlice","apply","value","slice"],"mappings":";;6iCA8CA,SAASA,EAAkBC,EAAOC,EAAOC,GACxC,IAAIC,EACAC,EAGJ,IAAMD,EAAIH,EAAM,EAAGG,GAAK,IACvBC,GAAMF,EAAKC,GAAM,GAAMF,EAAOE,GAC9BD,EAAKC,GAAMC,IAGNA,EAAI,IALiBD,KAS3B,OAAOD,CACR,CA8CA,SAASG,EAAeC,GACvB,IAAIC,EACAN,EACAD,EACAQ,EACAC,EACAC,EACAR,EACAS,EACAC,EACAC,EACAV,EAEJ,IAAMW,EAAeR,GACpB,MAAM,IAAIS,UAAWC,EAAQ,YAAaV,IAK3C,GAHAE,EAAO,CACNS,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNb,EAAUW,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaT,IAE3C,GAAKc,EAAYd,EAAS,YAAe,CACxC,IAAMe,EAAWf,EAAQgB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYT,EAAQgB,WAE/Df,EAAKS,UAAYV,EAAQgB,QACzB,CACD,CAMD,GAJAtB,EAAQK,EAAEL,OACVD,EAAQC,EAAMkB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXF,EAAIW,EAAOvB,MAEVS,GAAM,GAGPG,GAAKZ,EAAOD,EAAM,GAElBY,EAAKX,EADLU,EAAMX,EAAQ,GAIdG,GAAK,GAGLD,EAAMuB,EAAOzB,IAGRA,EAAM,GAAM,KAIjB0B,EADAjB,EAAO,CAAA,EACY,OAAQkB,GAC3BD,EAAajB,EAAM,SAAUmB,GAGxBC,GACJH,EAAajB,EAAMoB,EAAgBC,GAE7BrB,EAQP,SAASkB,IACR,IAAII,EACA3B,EAEJ,OADAD,GAAK,EACAO,GAAOP,GAAKU,EACT,CACNmB,MAAQ,IAIVD,EAAIE,EAAWC,MAAO,KAAMhC,GAG5BE,GAAMF,EAAKS,GAAQ,GAAMC,EACzBV,EAAKS,GAAQP,EACF,IAANA,GAEJL,EAAkBC,EAAOC,EAAOC,GAG1B,CACNiC,MAASC,EAAO9B,EAAGyB,GAAG,EAAMvB,EAAKS,UACjCe,MAAQ,GAET,CASD,SAASJ,EAAKO,GAEb,OADAzB,GAAM,EACDQ,UAAUC,OACP,CACNgB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASF,IACR,OAAOzB,EAAeC,EAAGE,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 133b323..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d2ee759e7693daa1cae3cc993e4bc14373cc5d84 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 17:39:47 +0000 Subject: [PATCH 05/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 51 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 243 - package.json | 70 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 594 -- test/test.js | 594 -- 41 files changed, 6207 insertions(+), 5075 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -219,7 +212,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -281,9 +274,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdcc55d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(n,r){return function(){return r||n((r={exports:{}}).exports,r),r.exports}};var b=j(function(G,w){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),E=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),P=require('@stdlib/assert-has-own-property/dist'),c=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),k=require('@stdlib/ndarray-base-numel/dist'),L=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/slice-multi/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function z(n,r,a){var e,i;for(e=n-3;e>=0&&(i=(a[e]+1)%r[e],a[e]=i,!(i>0));e--);return a}function g(n){var r,a,e,i,u,v,t,o,y,s,m;if(!F(n))throw new TypeError(p('null4f',n));if(i={writable:!1},arguments.length>1){if(r=arguments[1],!E(r))throw new TypeError(p('null2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(p('null2o',"readonly",r.readonly));i.writable=!r.readonly}}if(a=n.shape,e=a.length,e<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=k(a),s===0&&(v=!0),s/=a[e-2],o=e-1,y=a[o],m=-1,t=S(e),t[e-2]=null,u={},f(u,"next",q),f(u,"return",h),c&&f(u,c,O),u;function q(){var l,d;return m+=1,v||m>=s?{done:!0}:(l=V.apply(null,t),d=(t[o]+1)%y,t[o]=d,d===0&&z(e,a,t),{value:L(n,l,!0,i.writable),done:!1})}function h(l){return v=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return g(n,i)}}w.exports=g -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d82f912..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar MultiSlice = require( '@stdlib/slice-multi' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Increments stack indices.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {NonNegativeIntegerArray} idx - current indices\n* @returns {NonNegativeIntegerArray} updated indices\n*/\nfunction incrementIndices( ndims, shape, idx ) {\n\tvar i;\n\tvar j;\n\n\t// Search for the first dimension in which we don't have to \"carry the one\"...\n\tfor ( i = ndims-3; i >= 0; i-- ) {\n\t\tj = ( idx[ i ] + 1 ) % shape[ i ];\n\t\tidx[ i ] = j;\n\n\t\t// If the current index value is greater than zero, we can continue iterating within the current sub-array...\n\t\tif ( j > 0 ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t}\n\t}\n\t// Retrieve the input array shape:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tincrementIndices( ndims, shape, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAS,QAAS,uBAAwB,EAc9C,SAASC,EAAkBC,EAAOC,EAAOC,EAAM,CAC9C,IAAIC,EACAC,EAGJ,IAAMD,EAAIH,EAAM,EAAGG,GAAK,IACvBC,GAAMF,EAAKC,CAAE,EAAI,GAAMF,EAAOE,CAAE,EAChCD,EAAKC,CAAE,EAAIC,EAGN,EAAAA,EAAI,IALiBD,IAK1B,CAID,OAAOD,CACR,CA8CA,SAASG,EAAeC,EAAI,CAC3B,IAAIC,EACAN,EACAD,EACAQ,EACAC,EACAC,EACAR,EACAS,EACAC,EACAC,EACAV,EAEJ,GAAK,CAACZ,EAAee,CAAE,EACtB,MAAM,IAAI,UAAWR,EAAQ,oEAAqEQ,CAAE,CAAE,EAKvG,GAHAE,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAD,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWT,EAAQ,qEAAsES,CAAQ,CAAE,EAE9G,GAAKf,EAAYe,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWT,EAAQ,+DAAgE,WAAYS,EAAQ,QAAS,CAAE,EAE7HC,EAAK,SAAW,CAACD,EAAQ,QAC1B,CACD,CAMA,GAJAN,EAAQK,EAAE,MACVN,EAAQC,EAAM,OAGTD,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAa,EAAIlB,EAAOM,CAAM,EACZY,IAAM,IACVH,EAAM,IAGPG,GAAKZ,EAAOD,EAAM,CAAE,EACpBW,EAAMX,EAAQ,EACdY,EAAKX,EAAOU,CAAI,EAGhBR,EAAI,GAGJD,EAAMR,EAAOM,CAAM,EAGnBE,EAAKF,EAAM,CAAE,EAAI,KAGjBS,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQK,CAAK,EAChC1B,EAAaqB,EAAM,SAAUM,CAAI,EAG5BtB,GACJL,EAAaqB,EAAMhB,EAAgBuB,CAAQ,EAErCP,EAQP,SAASK,GAAO,CACf,IAAIG,EACAb,EAEJ,OADAD,GAAK,EACAO,GAAOP,GAAKU,EACT,CACN,KAAQ,EACT,GAGDI,EAAIpB,EAAW,MAAO,KAAMK,CAAI,EAGhCE,GAAMF,EAAKS,CAAI,EAAI,GAAMC,EACzBV,EAAKS,CAAI,EAAIP,EACRA,IAAM,GAEVL,EAAkBC,EAAOC,EAAOC,CAAI,EAG9B,CACN,MAASN,EAAOU,EAAGW,EAAG,GAAMT,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASO,EAAKG,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOX,EAAeC,EAAGE,CAAK,CAC/B,CACD,CAKArB,EAAO,QAAUkB,ICxLjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "numel", "slice", "MultiSlice", "format", "incrementIndices", "ndims", "shape", "idx", "i", "j", "nditerColumns", "x", "options", "opts", "iter", "FLG", "dim", "S0", "N", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 7717763..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,51 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0b52073..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b2a1754..a99dbef 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..05a297e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function p(e,r,t){var s,n;for(s=e-3;s>=0&&(n=(t[s]+1)%r[s],t[s]=n,!(n>0));s--);return t}function j(h){var v,f,u,b,c,y,g,w,x,E,T;if(!s(h))throw new TypeError(a("null4f,Pc",h));if(b={writable:!1},arguments.length>1){if(!r(v=arguments[1]))throw new TypeError(a("null2V,FD",v));if(n(v,"readonly")){if(!t(v.readonly))throw new TypeError(a("null2o,GE","readonly",v.readonly));b.writable=!v.readonly}}if(f=h.shape,(u=f.length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(E=d(f))&&(y=!0),E/=f[u-2],x=f[w=u-1],T=-1,(g=o(u))[u-2]=null,e(c={},"next",F),e(c,"return",k),i&&e(c,i,z),c;function F(){var e,r;return T+=1,y||T>=E?{done:!0}:(e=m.apply(null,g),r=(g[w]+1)%x,g[w]=r,0===r&&p(u,f,g),{value:l(h,e,!0,b.writable),done:!1})}function k(e){return y=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return j(h,b)}}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f350ffd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Increments stack indices.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {NonNegativeIntegerArray} idx - current indices\n* @returns {NonNegativeIntegerArray} updated indices\n*/\nfunction incrementIndices( ndims, shape, idx ) {\n\tvar i;\n\tvar j;\n\n\t// Search for the first dimension in which we don't have to \"carry the one\"...\n\tfor ( i = ndims-3; i >= 0; i-- ) {\n\t\tj = ( idx[ i ] + 1 ) % shape[ i ];\n\t\tidx[ i ] = j;\n\n\t\t// If the current index value is greater than zero, we can continue iterating within the current sub-array...\n\t\tif ( j > 0 ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t}\n\t}\n\t// Retrieve the input array shape:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tincrementIndices( ndims, shape, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["incrementIndices","ndims","shape","idx","i","j","nditerColumns","x","options","opts","iter","FLG","dim","S0","N","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","done","MultiSlice","apply","value","slice"],"mappings":";;6iCA8CA,SAASA,EAAkBC,EAAOC,EAAOC,GACxC,IAAIC,EACAC,EAGJ,IAAMD,EAAIH,EAAM,EAAGG,GAAK,IACvBC,GAAMF,EAAKC,GAAM,GAAMF,EAAOE,GAC9BD,EAAKC,GAAMC,IAGNA,EAAI,IALiBD,KAS3B,OAAOD,CACR,CA8CA,SAASG,EAAeC,GACvB,IAAIC,EACAN,EACAD,EACAQ,EACAC,EACAC,EACAR,EACAS,EACAC,EACAC,EACAV,EAEJ,IAAMW,EAAeR,GACpB,MAAM,IAAIS,UAAWC,EAAQ,YAAaV,IAK3C,GAHAE,EAAO,CACNS,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNb,EAAUW,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaT,IAE3C,GAAKc,EAAYd,EAAS,YAAe,CACxC,IAAMe,EAAWf,EAAQgB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYT,EAAQgB,WAE/Df,EAAKS,UAAYV,EAAQgB,QACzB,CACD,CAMD,GAJAtB,EAAQK,EAAEL,OACVD,EAAQC,EAAMkB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXF,EAAIW,EAAOvB,MAEVS,GAAM,GAGPG,GAAKZ,EAAOD,EAAM,GAElBY,EAAKX,EADLU,EAAMX,EAAQ,GAIdG,GAAK,GAGLD,EAAMuB,EAAOzB,IAGRA,EAAM,GAAM,KAIjB0B,EADAjB,EAAO,CAAA,EACY,OAAQkB,GAC3BD,EAAajB,EAAM,SAAUmB,GAGxBC,GACJH,EAAajB,EAAMoB,EAAgBC,GAE7BrB,EAQP,SAASkB,IACR,IAAII,EACA3B,EAEJ,OADAD,GAAK,EACAO,GAAOP,GAAKU,EACT,CACNmB,MAAQ,IAIVD,EAAIE,EAAWC,MAAO,KAAMhC,GAG5BE,GAAMF,EAAKS,GAAQ,GAAMC,EACzBV,EAAKS,GAAQP,EACF,IAANA,GAEJL,EAAkBC,EAAOC,EAAOC,GAG1B,CACNiC,MAASC,EAAO9B,EAAGyB,GAAG,EAAMvB,EAAKS,UACjCe,MAAQ,GAET,CASD,SAASJ,EAAKO,GAEb,OADAzB,GAAM,EACDQ,UAAUC,OACP,CACNgB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASF,IACR,OAAOzB,EAAeC,EAAGE,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 adc9748..0000000 --- a/lib/main.js +++ /dev/null @@ -1,243 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Increments stack indices. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {NonNegativeIntegerArray} shape - array shape -* @param {NonNegativeIntegerArray} idx - current indices -* @returns {NonNegativeIntegerArray} updated indices -*/ -function incrementIndices( ndims, shape, idx ) { - var i; - var j; - - // Search for the first dimension in which we don't have to "carry the one"... - for ( i = ndims-3; i >= 0; i-- ) { - j = ( idx[ i ] + 1 ) % shape[ i ]; - idx[ i ] = j; - - // If the current index value is greater than zero, we can continue iterating within the current sub-array... - if ( j > 0 ) { - break; - } - } - return idx; -} - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - } - } - // Retrieve the input array shape: - shape = x.shape; - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = MultiSlice.apply( null, idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - incrementIndices( ndims, shape, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index b6e02ba..80882ba 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-slice": "github:stdlib-js/ndarray-slice#main", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9558d01 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index f71f253..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,594 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5bb8a39..0000000 --- a/test/test.js +++ /dev/null @@ -1,594 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 44f965e7c2afc2366ac4c6ab536e3fe61ae8ed0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 12:30:37 +0000 Subject: [PATCH 06/82] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9acccf1..e41ebe6 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From f6a1ccfa58394eca3da095e0cfe6fe66997aafa0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 15:06:31 +0000 Subject: [PATCH 07/82] Remove files --- index.d.ts | 83 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6265 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 a99dbef..0000000 --- a/index.d.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } 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). - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 05a297e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function p(e,r,t){var s,n;for(s=e-3;s>=0&&(n=(t[s]+1)%r[s],t[s]=n,!(n>0));s--);return t}function j(h){var v,f,u,b,c,y,g,w,x,E,T;if(!s(h))throw new TypeError(a("null4f,Pc",h));if(b={writable:!1},arguments.length>1){if(!r(v=arguments[1]))throw new TypeError(a("null2V,FD",v));if(n(v,"readonly")){if(!t(v.readonly))throw new TypeError(a("null2o,GE","readonly",v.readonly));b.writable=!v.readonly}}if(f=h.shape,(u=f.length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(E=d(f))&&(y=!0),E/=f[u-2],x=f[w=u-1],T=-1,(g=o(u))[u-2]=null,e(c={},"next",F),e(c,"return",k),i&&e(c,i,z),c;function F(){var e,r;return T+=1,y||T>=E?{done:!0}:(e=m.apply(null,g),r=(g[w]+1)%x,g[w]=r,0===r&&p(u,f,g),{value:l(h,e,!0,b.writable),done:!1})}function k(e){return y=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return j(h,b)}}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f350ffd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Increments stack indices.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {NonNegativeIntegerArray} idx - current indices\n* @returns {NonNegativeIntegerArray} updated indices\n*/\nfunction incrementIndices( ndims, shape, idx ) {\n\tvar i;\n\tvar j;\n\n\t// Search for the first dimension in which we don't have to \"carry the one\"...\n\tfor ( i = ndims-3; i >= 0; i-- ) {\n\t\tj = ( idx[ i ] + 1 ) % shape[ i ];\n\t\tidx[ i ] = j;\n\n\t\t// If the current index value is greater than zero, we can continue iterating within the current sub-array...\n\t\tif ( j > 0 ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t}\n\t}\n\t// Retrieve the input array shape:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tincrementIndices( ndims, shape, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["incrementIndices","ndims","shape","idx","i","j","nditerColumns","x","options","opts","iter","FLG","dim","S0","N","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","done","MultiSlice","apply","value","slice"],"mappings":";;6iCA8CA,SAASA,EAAkBC,EAAOC,EAAOC,GACxC,IAAIC,EACAC,EAGJ,IAAMD,EAAIH,EAAM,EAAGG,GAAK,IACvBC,GAAMF,EAAKC,GAAM,GAAMF,EAAOE,GAC9BD,EAAKC,GAAMC,IAGNA,EAAI,IALiBD,KAS3B,OAAOD,CACR,CA8CA,SAASG,EAAeC,GACvB,IAAIC,EACAN,EACAD,EACAQ,EACAC,EACAC,EACAR,EACAS,EACAC,EACAC,EACAV,EAEJ,IAAMW,EAAeR,GACpB,MAAM,IAAIS,UAAWC,EAAQ,YAAaV,IAK3C,GAHAE,EAAO,CACNS,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNb,EAAUW,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaT,IAE3C,GAAKc,EAAYd,EAAS,YAAe,CACxC,IAAMe,EAAWf,EAAQgB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYT,EAAQgB,WAE/Df,EAAKS,UAAYV,EAAQgB,QACzB,CACD,CAMD,GAJAtB,EAAQK,EAAEL,OACVD,EAAQC,EAAMkB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXF,EAAIW,EAAOvB,MAEVS,GAAM,GAGPG,GAAKZ,EAAOD,EAAM,GAElBY,EAAKX,EADLU,EAAMX,EAAQ,GAIdG,GAAK,GAGLD,EAAMuB,EAAOzB,IAGRA,EAAM,GAAM,KAIjB0B,EADAjB,EAAO,CAAA,EACY,OAAQkB,GAC3BD,EAAajB,EAAM,SAAUmB,GAGxBC,GACJH,EAAajB,EAAMoB,EAAgBC,GAE7BrB,EAQP,SAASkB,IACR,IAAII,EACA3B,EAEJ,OADAD,GAAK,EACAO,GAAOP,GAAKU,EACT,CACNmB,MAAQ,IAIVD,EAAIE,EAAWC,MAAO,KAAMhC,GAG5BE,GAAMF,EAAKS,GAAQ,GAAMC,EACzBV,EAAKS,GAAQP,EACF,IAANA,GAEJL,EAAkBC,EAAOC,EAAOC,GAG1B,CACNiC,MAASC,EAAO9B,EAAGyB,GAAG,EAAMvB,EAAKS,UACjCe,MAAQ,GAET,CASD,SAASJ,EAAKO,GAEb,OADAzB,GAAM,EACDQ,UAAUC,OACP,CACNgB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASF,IACR,OAAOzB,EAAeC,EAAGE,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9558d01..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 911a69fb13a03421373066fcedf595363f50da76 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 15:07:42 +0000 Subject: [PATCH 08/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 220 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 41 files changed, 6207 insertions(+), 4507 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -219,7 +212,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -281,9 +274,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d2a786a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(B,q){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),w=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-base-numel/dist'),L=require('@stdlib/ndarray-base-slice/dist'),R=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,V=require('@stdlib/slice-multi/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e){var r,n,i,t,o,d,a,u,p,s,m;if(!C(e))throw new TypeError(v('null4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('null2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('null2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=e.shape,i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=x(n),s===0&&(d=!0),s/=n[i-2],u=i-1,p=n[u],m=-1,a=S(i),a[i-2]=null,o={},y(o,"next",h),y(o,"return",c),w&&y(o,w,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=V.apply(null,a),f=(a[u]+1)%p,a[u]=f,f===0&&(a=R(n,"row-major",a,u-2,a)),{value:L(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return g(e,t)}}q.exports=g -});var k=b();module.exports=k; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2102aed..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar MultiSlice = require( '@stdlib/slice-multi' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAa,QAAS,qBAAsB,EAC5CC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACtB,EAAeW,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACd,EAAec,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKV,EAAYU,EAAS,UAAW,EAAI,CACxC,GAAK,CAACb,EAAWa,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYd,EAAYU,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQF,EAAE,MACVG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMd,EAAOU,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRnB,EAAamB,EAAM,OAAQO,CAAK,EAChC1B,EAAamB,EAAM,SAAUQ,CAAI,EAG5BrB,GACJN,EAAamB,EAAMb,EAAgBsB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAW,MAAO,KAAMU,CAAI,EAGhCS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAnB,EAAO,QAAUc,ICjKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "numel", "slice", "nextCartesianIndex", "MultiSlice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0b52073..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..84a3ce4 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(v){var b,u,f,y,g,c,w,x,E,T,F;if(!s(v))throw new TypeError(j("invalid argument. First argument must be an ndarray. Value: `%s`.",v));if(y={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(j("invalid argument. Options argument must be an object. Value: `%s`.",b));if(i(b,"readonly")){if(!t(b.readonly))throw new TypeError(j("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",b.readonly));if(y.writable=!b.readonly,y.writable&&n(v))throw new Error(j("invalid option. Cannot write to read-only array."))}}if((f=(u=v.shape).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(T=a(u))&&(c=!0),T/=u[f-2],E=u[x=f-1],F=-1,(w=d(f))[f-2]=null,e(g={},"next",O),e(g,"return",V),o&&e(g,o,k),g;function O(){var e,r;return F+=1,c||F>=T?{done:!0}:(e=p.apply(null,w),r=(w[x]+1)%E,w[x]=r,0===r&&(w=l(u,"row-major",w,x-2,w)),{value:m(v,e,!0,y.writable),done:!1})}function V(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function k(){return h(v,y)}}export{h as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9d3e588 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","MultiSlice","apply","nextCartesianIndex","value","slice"],"mappings":";;8vCAiFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQF,EAAEE,OACIe,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIc,EAAOtB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMkB,EAAOtB,IAGRA,EAAM,GAAM,KAIjBuB,EADArB,EAAO,CAAA,EACY,OAAQsB,GAC3BD,EAAarB,EAAM,SAAUuB,GAGxBC,GACJH,EAAarB,EAAMwB,EAAgBC,GAE7BzB,EAQP,SAASsB,IACR,IAAII,EACAC,EAEJ,OADArB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNuB,MAAQ,IAIVF,EAAIG,EAAWC,MAAO,KAAM5B,GAG5ByB,GAAMzB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQwB,EACF,IAANA,IAEJzB,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAG+B,GAAG,EAAM3B,EAAKW,UACjCkB,MAAQ,GAET,CASD,SAASL,EAAKS,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAO/B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 3d37759..0000000 --- a/lib/main.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var MultiSlice = require( '@stdlib/slice-multi' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = x.shape; - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = MultiSlice.apply( null, idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index e41ebe6..80882ba 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "github:stdlib-js/ndarray-base-next-cartesian-index#main", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "github:stdlib-js/ndarray-slice#main", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9dc13a3 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 8b0e0f06f75275c2dd75a5f075d28dc5fb323dfa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:06:08 +0000 Subject: [PATCH 09/82] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7939e09..a85cfa2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 74c69a1b7c31f6e7ec32af834daad0f5686040f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:06:47 +0000 Subject: [PATCH 10/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 84a3ce4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(v){var b,u,f,y,g,c,w,x,E,T,F;if(!s(v))throw new TypeError(j("invalid argument. First argument must be an ndarray. Value: `%s`.",v));if(y={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(j("invalid argument. Options argument must be an object. Value: `%s`.",b));if(i(b,"readonly")){if(!t(b.readonly))throw new TypeError(j("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",b.readonly));if(y.writable=!b.readonly,y.writable&&n(v))throw new Error(j("invalid option. Cannot write to read-only array."))}}if((f=(u=v.shape).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(T=a(u))&&(c=!0),T/=u[f-2],E=u[x=f-1],F=-1,(w=d(f))[f-2]=null,e(g={},"next",O),e(g,"return",V),o&&e(g,o,k),g;function O(){var e,r;return F+=1,c||F>=T?{done:!0}:(e=p.apply(null,w),r=(w[x]+1)%E,w[x]=r,0===r&&(w=l(u,"row-major",w,x-2,w)),{value:m(v,e,!0,y.writable),done:!1})}function V(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function k(){return h(v,y)}}export{h as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9d3e588..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","MultiSlice","apply","nextCartesianIndex","value","slice"],"mappings":";;8vCAiFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQF,EAAEE,OACIe,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIc,EAAOtB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMkB,EAAOtB,IAGRA,EAAM,GAAM,KAIjBuB,EADArB,EAAO,CAAA,EACY,OAAQsB,GAC3BD,EAAarB,EAAM,SAAUuB,GAGxBC,GACJH,EAAarB,EAAMwB,EAAgBC,GAE7BzB,EAQP,SAASsB,IACR,IAAII,EACAC,EAEJ,OADArB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNuB,MAAQ,IAIVF,EAAIG,EAAWC,MAAO,KAAM5B,GAG5ByB,GAAMzB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQwB,EACF,IAANA,IAEJzB,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAG+B,GAAG,EAAM3B,EAAKW,UACjCkB,MAAQ,GAET,CASD,SAASL,EAAKS,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAO/B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9dc13a3..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7f9ffd8a890dc74539a66cda504bec9880e3aaeb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:08:01 +0000 Subject: [PATCH 11/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 41 files changed, 6207 insertions(+), 4517 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -219,7 +212,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -281,9 +274,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d05c6bb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-is-boolean/dist').isPrimitive,T=require('@stdlib/assert-is-ndarray-like/dist'),C=require('@stdlib/ndarray-base-assert-is-read-only/dist'),F=require('@stdlib/assert-has-own-property/dist'),w=require('@stdlib/symbol-iterator/dist'),P=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-multi/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e){var r,n,i,t,u,d,a,o,p,s,m;if(!T(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(F(r,"readonly")){if(!S(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&C(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],o=i-1,p=n[o],m=-1,a=P(i),a[i-2]=null,u={},y(u,"next",h),y(u,"return",c),w&&y(u,w,O),u;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k.apply(null,a),f=(a[o]+1)%p,a[o]=f,f===0&&(a=V(n,"row-major",a,o-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return g(e,t)}}q.exports=g -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f2342bf..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar MultiSlice = require( '@stdlib/slice-multi' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAa,QAAS,qBAAsB,EAC5CC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAW,MAAO,KAAMU,CAAI,EAGhCS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "MultiSlice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0b52073..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6c6ab8c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,y,g,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(g={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(g.writable=!u.readonly,g.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[y-2],T=f[E=y-1],O=-1,(x=o(y))[y-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=j.apply(null,x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=p(f,"row-major",x,E-2,x)),{value:l(b,e,!0,g.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,g)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..22447c0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","MultiSlice","apply","nextCartesianIndex","value","slice"],"mappings":";;s1CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAWC,MAAO,KAAM7B,GAG5B0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM8B,EAAoBnC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN+B,MAASC,EAAOvC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKS,GAEb,OADAhC,GAAM,EACDU,UAAUC,OACP,CACNqB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 b1f6604..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var MultiSlice = require( '@stdlib/slice-multi' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = MultiSlice.apply( null, idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index a85cfa2..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "github:stdlib-js/ndarray-base-next-cartesian-index#main", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "github:stdlib-js/ndarray-slice#main", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..323723e --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 609968d805b0c101ea7717a92c3fd6a23955a1d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:08:31 +0000 Subject: [PATCH 12/82] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a140b1..6181905 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.1.0-esm/index.mjs'; ``` #### nditerColumns( x\[, options] ) @@ -158,7 +158,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.1.0-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From c317ddfc4fabeb41447ffefe4f12d584a22c2d1b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:08:32 +0000 Subject: [PATCH 13/82] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6181905..0305902 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-columns/tags). For example, + ```javascript import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.1.0-esm/index.mjs'; ``` @@ -158,7 +163,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.1.0-esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 8a4861d3ed243426042543fe530d01d9d356b5e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 20:38:07 +0000 Subject: [PATCH 14/82] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2495f9..185af83 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "github:stdlib-js/slice-base-args2multislice#main", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 0379e15899f47e5aa41e4864a59bc431ff4462cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 20:40:44 +0000 Subject: [PATCH 15/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6c6ab8c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,y,g,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(g={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(g.writable=!u.readonly,g.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[y-2],T=f[E=y-1],O=-1,(x=o(y))[y-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=j.apply(null,x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=p(f,"row-major",x,E-2,x)),{value:l(b,e,!0,g.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,g)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 22447c0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport MultiSlice from '@stdlib/slice-multi';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = MultiSlice.apply( null, idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","MultiSlice","apply","nextCartesianIndex","value","slice"],"mappings":";;s1CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAWC,MAAO,KAAM7B,GAG5B0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM8B,EAAoBnC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN+B,MAASC,EAAOvC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKS,GAEb,OADAhC,GAAM,EACDU,UAAUC,OACP,CACNqB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 323723e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From de45fbd01fcf13be41ff27e1819938b9ed3739f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 20:41:49 +0000 Subject: [PATCH 16/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 41 files changed, 6207 insertions(+), 4517 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -219,7 +212,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -281,9 +274,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0b52073..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0e3b63e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dea2732 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q2CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 df5a646..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 185af83..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "github:stdlib-js/slice-base-args2multislice#main", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..32bfa25 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 0e8deb80b263502632f0e9a014c5ac31e7a13fdf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 17:18:06 +0000 Subject: [PATCH 17/82] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..4a3c794 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 2cb4ef4..83294be 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From fbf88d1d8f94de8f207e9e0fc87a6f935ffa11ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:36:34 +0000 Subject: [PATCH 18/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0e3b63e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dea2732..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q2CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 32bfa25..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a21390d314ad8c645a2ae3c313fd70d8c078c84a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:37:33 +0000 Subject: [PATCH 19/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 42 files changed, 6207 insertions(+), 4518 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index bc39c8d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:35:03.055Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -219,7 +212,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -281,9 +274,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0b52073..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15e0670 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ddb4d69 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 4a3c794..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 83294be..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cc4f290 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From ffc2c6adef165f1e076e3e84458f6742b736d7f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:27:27 +0000 Subject: [PATCH 20/82] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..4a3c794 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 2cb4ef4..83294be 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 3709badfc2ed060046cbcfc0d39b9b4fc170187f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:28:20 +0000 Subject: [PATCH 21/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15e0670..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ddb4d69..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cc4f290..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From accecbd2e64212cf40f357f1278097fff484bc1e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:29:19 +0000 Subject: [PATCH 22/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 41 files changed, 6207 insertions(+), 4517 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -219,7 +212,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -281,9 +274,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15e0670 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ddb4d69 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 4a3c794..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 83294be..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8c8a609 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 95d1b44489096294272eeffc3e920e31d7a5f018 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 12:50:37 +0000 Subject: [PATCH 23/82] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..4a3c794 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index efd08a1..bc484b3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From b56ded00e139212cc4e872387607726161b52330 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 16:41:11 +0000 Subject: [PATCH 24/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15e0670..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ddb4d69..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8c8a609..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c115bc50bed3e3f76aecccc8dbbcd8b8da14d12b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 16:42:14 +0000 Subject: [PATCH 25/82] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 41 files changed, 6209 insertions(+), 4519 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -227,7 +220,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]. @@ -289,15 +282,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15e0670 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ddb4d69 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 4a3c794..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index bc484b3..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3681ef2 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From bc4d471eb3485da4e76559f4f7c4304a85e62a73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:27:11 +0000 Subject: [PATCH 26/82] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..4a3c794 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 3fa4fed..e2062c5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 4bb03a34f231221faddd174df07318e6cd70333f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:32:40 +0000 Subject: [PATCH 27/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15e0670..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ddb4d69..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3681ef2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d531a0549e55aaa94996a5b7d4d0b4ce1622f7c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:33:30 +0000 Subject: [PATCH 28/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 42 files changed, 6209 insertions(+), 4515 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cd428b1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:40:14.915Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index c3e4a99..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -227,7 +220,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]. @@ -289,15 +282,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e6808e7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15e0670 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ddb4d69 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 4a3c794..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index e2062c5..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e760cfa --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 6ddfe419bbf80c1d6b8d6921434d06069a485ae7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:00:31 +0000 Subject: [PATCH 29/82] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ffeed86..35840e7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 2e87072bb81bb1220b96a723c3237654c0acc11f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:37:28 +0000 Subject: [PATCH 30/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15e0670..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-2],T=c[E=y-1],k=-1,(x=o(y))[y-2]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r;return k+=1,w||k>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(c,"row-major",x,E-2,x)),{value:a(b,e,!0,u.writable),done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ddb4d69..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e760cfa..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0041b49e31e46eb904cd7c3fda2ef8c122a69ec5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:37:53 +0000 Subject: [PATCH 31/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 43 files changed, 6209 insertions(+), 4521 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7956320..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:09:32.339Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d12b3cb..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -227,7 +220,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]. @@ -289,15 +282,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 28e7548..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 84e7d6e..b31debb 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b25b7a8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0476651 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;42CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 df5a646..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 35840e7..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48e7344 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From ce33d8a1039193365f42fd47ac1bade998737873 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:33:07 +0000 Subject: [PATCH 32/82] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ffeed86..35840e7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 92c2b3ac3915a1ce1bb0c46b3b8ee4ca5d56741f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:54:56 +0000 Subject: [PATCH 33/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 b31debb..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b25b7a8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0476651..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;42CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48e7344..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cc2273fe3a17f4f7d51aaed9b61b52e90ae65ea9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:55:17 +0000 Subject: [PATCH 34/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 43 files changed, 6209 insertions(+), 4526 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 88bc2ba..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:59:17.559Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 43a323e..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/columns) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d12b3cb..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b25b7a8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0476651 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;42CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 df5a646..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 35840e7..5bb9b96 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..06d3311 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From b40359b82b0300cc633b1ac9677087da6900bc44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:13:21 +0000 Subject: [PATCH 35/82] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c57dda..b570280 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.0", "@stdlib/ndarray-shape": "^0.2.0", "@stdlib/slice-base-args2multislice": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/symbol-iterator": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" From 1221d9d9a058d098051083d6f89b10538fd6e776 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:10:30 +0000 Subject: [PATCH 36/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b25b7a8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0476651..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;42CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 06d3311..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 27c3f062a736f9af1a4669f053ca4d4388914c2b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:11:24 +0000 Subject: [PATCH 37/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 -- 42 files changed, 6209 insertions(+), 4529 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 1cb35ca..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c41e0d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0476651 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;42CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 df5a646..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index b570280..3cfcef0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.0", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-slice": "^0.2.0", - "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/slice-base-args2multislice": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/symbol-iterator": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..14bb4bb --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From cbc120afdac85869087f5f6d3951d83d54882cbb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:52:47 +0000 Subject: [PATCH 38/82] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5621757..9acdca8 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.0-esm/index.mjs'; ``` #### nditerColumns( x\[, options] ) @@ -158,7 +158,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.0-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 7d212d94bf0af768dbe2123fb1ac660ca171233f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:52:47 +0000 Subject: [PATCH 39/82] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9acdca8..0fb1988 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-columns/tags). For example, + ```javascript import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.0-esm/index.mjs'; ``` @@ -158,7 +163,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.0-esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From b62ba7c5ba1b615caf93c2c5af1d5457b8f20969 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:07:37 +0000 Subject: [PATCH 40/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index a7c7c63..85a08e5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 3b25f86ffa1093f271c9e92199d24f4c6c67e714 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:58:26 +0000 Subject: [PATCH 41/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6269 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c41e0d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,y,c,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(y={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(y.writable=!u.readonly,y.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-2],T=f[E=g-1],O=-1,(x=o(g))[g-2]=null,e(c={},"next",V),e(c,"return",k),d&&e(c,d,z),c;function V(){var e,r;return O+=1,w||O>=F?{done:!0}:(e=p(x),r=(x[E]+1)%T,x[E]=r,0===r&&(x=j(f,"row-major",x,E-2,x)),{value:l(b,e,!0,y.writable),done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,y)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0476651..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","s","j","done","args2multislice","nextCartesianIndex","value","slice"],"mappings":";;42CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA8BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EAEJ,OADAtB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNwB,MAAQ,IAIVF,EAAIG,EAAiB5B,GAGrB0B,GAAM1B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQyB,EACF,IAANA,IAEJ1B,EAAM6B,EAAoBlC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACN8B,MAASC,EAAOtC,EAAGgC,GAAG,EAAM5B,EAAKW,UACjCmB,MAAQ,GAET,CASD,SAASL,EAAKQ,GAEb,OADA/B,GAAM,EACDU,UAAUC,OACP,CACNoB,MAASA,EACTH,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAOhC,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 14bb4bb..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2c559d6f27635178db5a30504b10670ee1a1017e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:58:51 +0000 Subject: [PATCH 42/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 42 files changed, 4874 insertions(+), 4524 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6577983 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 85a08e5..b673b50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-slice": "^0.2.0", - "@stdlib/ndarray-to-array": "^0.2.0", - "@stdlib/ndarray-zeros": "^0.2.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5c53ff7 --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 7626fafbefe7a79c320757150d9c79a949a67e63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:33:37 +0000 Subject: [PATCH 43/82] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61152d5..34e19f3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.1-esm/index.mjs'; ``` #### nditerColumns( x\[, options] ) @@ -158,7 +158,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.1-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 673317fb6793d163d508814868ac3b957dfcc20f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:33:37 +0000 Subject: [PATCH 44/82] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 34e19f3..753060d 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-columns/tags). For example, + ```javascript import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.1-esm/index.mjs'; ``` @@ -158,7 +163,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.1-esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 9f814884cd2c5060492e36547f887924ccc840c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:53:17 +0000 Subject: [PATCH 45/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index eba1079..dee3c64 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 59ee30de807ae88f0c84a2a29431a49482ff0833 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:36:12 +0000 Subject: [PATCH 46/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6577983..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5c53ff7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7c985d0f07d68707879fade0f2163a1f74f35420 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:36:33 +0000 Subject: [PATCH 47/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 43 files changed, 4874 insertions(+), 4526 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index be67a79..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:41:26.810Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06db1ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index dee3c64..b673b50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01131b6 --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 23585237220d47d0dfa7f33431fe69e5fd20e96e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:10:55 +0000 Subject: [PATCH 48/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index eba1079..dee3c64 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 753b22246d5f6bbd0c9a5bdbd83ef55b91bec27e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:31:02 +0000 Subject: [PATCH 49/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06db1ba..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 01131b6..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5de2d1bed5e28279bbeb0325837f7dc032b1326f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:31:20 +0000 Subject: [PATCH 50/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 43 files changed, 4874 insertions(+), 4529 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e7a44f9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:59:38.603Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06db1ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index dee3c64..b673b50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01131b6 --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 02efd7607cdbfd024dfc813db8eae615c7979ba5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:28:35 +0000 Subject: [PATCH 51/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index eba1079..dee3c64 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 3aa6e681fa95c6547070fddb562b16b854972920 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:49:02 +0000 Subject: [PATCH 52/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06db1ba..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 01131b6..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ec3dbe9d8a1c3baaff2d244aa8b98c23350ce17f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:49:22 +0000 Subject: [PATCH 53/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 42 files changed, 4874 insertions(+), 4530 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0163abd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,C=require('@stdlib/assert-is-ndarray-like/dist'),F=require('@stdlib/ndarray-base-assert-is-read-only/dist'),P=require('@stdlib/assert-has-own-property/dist'),g=require('@stdlib/symbol-iterator/dist'),S=require('@stdlib/array-base-zeros/dist'),x=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),V=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,k=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v('1jp4f',e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v('1jp2V',r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v('1jp2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v('1jpF4'))}}if(n=x(e),i=n.length,i<2)throw new TypeError(v('1jpF2'));return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p -});var z=b();module.exports=z; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06db1ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index dee3c64..b673b50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01131b6 --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 6f1597210834c405f7c75724982b5070aed0caac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:45:49 +0000 Subject: [PATCH 54/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index 2e3a002..9a82de4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From d056b5d9b93a1c6fe9293ae7d8ff61bac9257562 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:00:07 +0000 Subject: [PATCH 55/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06db1ba..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 01131b6..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3213a0a6b73002619eac1119f758f744c0600c6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:00:25 +0000 Subject: [PATCH 56/82] 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 | 123 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 42 files changed, 4874 insertions(+), 4675 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 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06321b2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 9a82de4..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e9c7507 --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 72a8f1008006314eba9289e3b6e4b1e8e5a80919 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:09:03 +0000 Subject: [PATCH 57/82] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65f75a9..f37c06e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.2-esm/index.mjs'; ``` #### nditerColumns( x\[, options] ) @@ -158,7 +158,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.2-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From c569de1c6122ddf3751180b1660bbc6ce59d5fe8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:09:04 +0000 Subject: [PATCH 58/82] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f37c06e..b3710f9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-columns/tags). For example, + ```javascript import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.2-esm/index.mjs'; ``` @@ -158,7 +163,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@v0.2.2-esm/index.mjs'; +import nditerColumns from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-columns@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From c64295b31a29c6e3f8ce7dfef1a9fc8e1d0a705d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 07:59:32 +0000 Subject: [PATCH 59/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index c44e38b..cdb1fa4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From c7dc7d25ba43f5073a4e1687b09b35107a16b2a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:52:44 +0000 Subject: [PATCH 60/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06321b2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e9c7507..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 07aeff3c9ddb0c6c01ac600a508809a043fca981 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:53:02 +0000 Subject: [PATCH 61/82] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 78 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 43 files changed, 4874 insertions(+), 4631 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 e7f2577..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:52:05.013Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 03a18c3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 2633645..d9eff13 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 { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1505472 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index cdb1fa4..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 75270cbd4c429d1833f2868c844c29819636a23d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 10 Aug 2024 23:11:00 +0000 Subject: [PATCH 62/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index c44e38b..cdb1fa4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 2bc3638b47133040d5809617250213d881dc871c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 10 Aug 2024 23:11:29 +0000 Subject: [PATCH 63/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 d9eff13..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { ndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: ndarray, options?: Options ): Iterator; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1505472..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c688d7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6ea60aef08364ae9874b28b1ea56d15a14c37574 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 10 Aug 2024 23:11:46 +0000 Subject: [PATCH 64/82] 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 | 157 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 42 files changed, 4874 insertions(+), 4709 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 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 82e9ee1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator> - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b3a8258..0386976 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..1505472 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index cdb1fa4..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 311b824e39689a18f94edd42ce3627d6053ca988 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:23:38 +0000 Subject: [PATCH 65/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index b78d630..f204c06 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 779251d18b79b5af0718fbeb5c4ca315fea42bbd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:51:09 +0000 Subject: [PATCH 66/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 0386976..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: typedndarray, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1505472..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c688d7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 886f2adcb6b05e40742ed4339f285c31316b0785 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:51:32 +0000 Subject: [PATCH 67/82] 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 | 157 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 43 files changed, 4874 insertions(+), 4710 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 1d7b0a5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:18:52.776Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 82e9ee1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator> - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b3a8258..0386976 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..1505472 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index f204c06..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 78056f6fe7ecfe3e9b0a2380b608e16c3bd35537 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:40:36 +0000 Subject: [PATCH 68/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index b78d630..f204c06 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 28ba09d088ebc9b686dfb5dc704993e10f7d1c57 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:22:54 +0000 Subject: [PATCH 69/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 0386976..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: typedndarray, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1505472..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c688d7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2f6167d5a0b8a077f7be295e5e70ce685a827d3e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:23:12 +0000 Subject: [PATCH 70/82] 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 | 157 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 43 files changed, 4874 insertions(+), 4710 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 95ffdd9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:31:02.464Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 82e9ee1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator> - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b3a8258..0386976 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..1505472 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index f204c06..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From c285ef7a52dfd1b444f83d9447bdac1c16c9999d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:27:17 +0000 Subject: [PATCH 71/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index b78d630..f204c06 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 3a8afa988f0c6aa7ce9dc3d3f50b2d4fd2b1a598 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:24:54 +0000 Subject: [PATCH 72/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 0386976..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: typedndarray, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1505472..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c688d7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 40a1540c2867f9dadb2c93c58625a188f4147c67 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:25:12 +0000 Subject: [PATCH 73/82] 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 | 157 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 43 files changed, 4874 insertions(+), 4710 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 02e6926..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:34:12.189Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 82e9ee1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator> - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b3a8258..0386976 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..1505472 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index f204c06..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From c3f5cca9e16ec37bf312ab67c5283cc8f6217362 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:08:05 +0000 Subject: [PATCH 74/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index 5b8dd29..9150db3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 2940252b4ea1f02bc1cd5176540355664ad4dab8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 04:16:56 +0000 Subject: [PATCH 75/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 0386976..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: typedndarray, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1505472..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c688d7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e4151eeebb6a9de0e2fe0858283bfd6a816a044e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 04:17:14 +0000 Subject: [PATCH 76/82] 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 | 157 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 44 files changed, 4874 insertions(+), 4815 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 f6af797..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:43:49.976Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 941f5e8..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 82e9ee1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator> - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b3a8258..0386976 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..1505472 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 9150db3..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 981b6d17be398bc73b875b34854f29f011be6b27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:32:55 +0000 Subject: [PATCH 77/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index 5b8dd29..9150db3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 9da048c4d67d8b8c0405ed6718ee9708c2826d26 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 02:10:34 +0000 Subject: [PATCH 78/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 0386976..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: typedndarray, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1505472..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c688d7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 332506e363511436531b544ce0151d447b67950f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 02:11:21 +0000 Subject: [PATCH 79/82] 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 | 157 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 44 files changed, 4874 insertions(+), 4818 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 dcae4b8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-07T01:28:15.992Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58f5344..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 82e9ee1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator> - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b3a8258..0386976 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..7aa47f2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 9150db3..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 4c7ae5d632a3eaac4e588d8f68f643db6e622a72 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 00:35:16 +0000 Subject: [PATCH 80/82] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index df5a646..09b4661 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerColumns( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jp4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerColumns( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerColumns( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1jpF2') ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index 5b8dd29..9150db3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 9c79ae0076997ca11e7a3e980d168a073b23e1a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 00:36:33 +0000 Subject: [PATCH 81/82] Remove files --- index.d.ts | 87 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4934 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 0386976..0000000 --- a/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param x - input value -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -declare function nditerColumns( x: typedndarray, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerColumns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7aa47f2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c8cec2c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c688d7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f4b0dabbf6f367f075398fe37b2665d25b037969 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 00:37:01 +0000 Subject: [PATCH 82/82] 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 | 157 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- 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 | 52 - docs/types/test.ts | 77 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 221 - package.json | 73 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 608 --- 44 files changed, 4874 insertions(+), 4818 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 65a436c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-19T00:34:28.088Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 58f5344..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/columns) 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 43a323e..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/columns) 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 7d566e6..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: '9 9 * * 4' - - # 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 + + ```
@@ -229,7 +220,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]. @@ -294,15 +285,15 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/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 86d77e5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'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 nditerColumns = 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 = nditerColumns( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ 1, xbuf.length ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerColumns( x ); - - 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 ec38668..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/columns" -%% click B href "https://github.com/stdlib-js/ndarray-iter-columns/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-columns/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-columns/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-columns/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-columns/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/columns -[production-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-columns/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-columns/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 e405f44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerColumns from '../docs/types/index'; -export = nditerColumns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b280285..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var E=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=E(function(G,q){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),j=require("@stdlib/assert-is-plain-object"),T=require("@stdlib/assert-is-boolean").isPrimitive,C=require("@stdlib/assert-is-ndarray-like"),F=require("@stdlib/ndarray-base-assert-is-read-only"),P=require("@stdlib/assert-has-own-property"),g=require("@stdlib/symbol-iterator"),S=require("@stdlib/array-base-zeros"),x=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),R=require("@stdlib/ndarray-base-slice"),V=require("@stdlib/ndarray-base-next-cartesian-index").assign,k=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function p(e){var r,n,i,t,o,d,a,u,y,s,m;if(!C(e))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!j(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(P(r,"readonly")){if(!T(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&F(e))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(n=x(e),i=n.length,i<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(n),s===0&&(d=!0),s/=n[i-2],u=i-1,y=n[u],m=-1,a=S(i),a[i-2]=null,o={},w(o,"next",h),w(o,"return",c),g&&w(o,g,O),o;function h(){var l,f;return m+=1,d||m>=s?{done:!0}:(l=k(a),f=(a[u]+1)%y,a[u]=f,f===0&&(a=V(n,"row-major",a,u-2,a)),{value:R(e,l,!0,t.writable),done:!1})}function c(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return p(e,t)}}q.exports=p});var z=b();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d8f5665..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerColumns;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-columns\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerColumns = require( '@stdlib/ndarray-iter-columns' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAG5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EAEJ,OADAL,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAIlB,EAAiBU,CAAI,EAGzBS,GAAMT,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIQ,EACRA,IAAM,IAEVT,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGe,EAAG,GAAMX,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASS,EAAKI,EAAQ,CAErB,OADAX,EAAM,GACD,UAAU,OACP,CACN,MAASW,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKApB,EAAO,QAAUe,IClKjB,IAAImB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerColumns", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S0", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bcbecb8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,52 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which iterates over each column in a matrix (or stack of - matrices). - - 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. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 1, 3 ] - > v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 82e9ee1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerColumns = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerColumns( zeros( [ 2, 2 ] ) ); // $ExpectType Iterator> - nditerColumns( zeros( [ 2, 2 ] ), {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerColumns( 123 ); // $ExpectError - nditerColumns( true ); // $ExpectError - nditerColumns( false ); // $ExpectError - nditerColumns( null ); // $ExpectError - nditerColumns( undefined ); // $ExpectError - nditerColumns( {} ); // $ExpectError - nditerColumns( [] ); // $ExpectError - nditerColumns( ( x: number ): number => x ); // $ExpectError - - nditerColumns( 123, {} ); // $ExpectError - nditerColumns( true, {} ); // $ExpectError - nditerColumns( false, {} ); // $ExpectError - nditerColumns( null, {} ); // $ExpectError - nditerColumns( undefined, {} ); // $ExpectError - nditerColumns( {}, {} ); // $ExpectError - nditerColumns( [], {} ); // $ExpectError - nditerColumns( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - nditerColumns( zeros( [ 2, 2 ] ), 'abc' ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), 123 ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), true ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), false ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), null ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), [] ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 'abc' } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': 123 } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': null } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': [] } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': {} } ); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerColumns(); // $ExpectError - nditerColumns( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f2a302e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over columns: -var it = nditerColumns( x ); - -// 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 b3a8258..0386976 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..7aa47f2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,T,F,k;if(!t(f))throw new TypeError(h("1jp4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1jp2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1jp2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1jpF4"))}}if((y=(c=m(f)).length)<2)throw new TypeError(h("1jpF2"));return 0===(F=l(c))&&(x=!0),F/=c[y-2],T=c[E=y-1],k=-1,(w=o(y))[y-2]=null,e(u={},"next",(function(){var e,r;if(k+=1,x||k>=F)return{done:!0};e=p(w),r=(w[E]+1)%T,w[E]=r,0===r&&(w=j(c,"row-major",w,E-2,w));return{value:a(f,e,!0,g.writable),done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c8cec2c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each column in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input value\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerColumns( x );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ 1, 3 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 2, 4 ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ 5, 7 ]\n*\n* // ...\n*/\nfunction nditerColumns( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S0;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jp4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jp2V', 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( '1jp2o', '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( '1jpF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1jpF2') );\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 columns across all stacks of matrices:\n\tN /= shape[ ndims-2 ];\n\tdim = ndims - 1;\n\tS0 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( ndims );\n\n\t// Set the second-to-last element to `null` to indicate that we want a full \"slice\" for the second-to-last dimension:\n\tidx[ ndims-2 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S0;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );\n\t\t}\n\t\t// Return the next column slice:\n\t\treturn {\n\t\t\t'value': slice( x, s, true, opts.writable ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerColumns( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerColumns;\n"],"names":["nditerColumns","x","options","shape","ndims","opts","iter","FLG","idx","dim","S0","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA8B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EAEJ,GADAlB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNoB,MAAQ,GAIVF,EAAIG,EAAiBxB,GAGrBsB,GAAMtB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQqB,EACF,IAANA,IAEJtB,EAAMyB,EAAoB9B,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN0B,MAASC,EAAOlC,EAAG4B,GAAG,EAAMxB,EAAKW,UACjCe,MAAQ,EAET,IAtCDH,EAAatB,EAAM,UA+CnB,SAAc4B,GAEb,GADA3B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAvDIK,GACJR,EAAatB,EAAM8B,GA8DpB,WACC,OAAOpC,EAAeC,EAAGI,EACzB,IA9DMC,CA+DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e493f96..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-columns -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerColumns = require( '@stdlib/ndarray-iter-columns' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ - -// 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 09b4661..0000000 --- a/lib/main.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each column in a matrix (or stack of matrices). -* -* @param {ndarray} x - input value -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerColumns( x ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ 1, 3 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 2, 4 ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ 5, 7 ] -* -* // ... -*/ -function nditerColumns( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S0; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jp4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jp2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1jp2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1jpF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1jpF2') ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of columns across all stacks of matrices: - N /= shape[ ndims-2 ]; - dim = ndims - 1; - S0 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = zeros( ndims ); - - // Set the second-to-last element to `null` to indicate that we want a full "slice" for the second-to-last dimension: - idx[ ndims-2 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S0; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx ); - } - // Return the next column slice: - return { - 'value': slice( x, s, true, opts.writable ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerColumns( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerColumns; diff --git a/package.json b/package.json index 9150db3..45b8813 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which iterates over each column in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-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..c688d7c --- /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 16cd3c9..0000000 --- a/test/test.js +++ /dev/null @@ -1,608 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerColumns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerColumns, '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() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - 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() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second 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() { - nditerColumns( zeros( [ 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerColumns( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerColumns( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': slice( x, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, 1 ), - 'done': false - }, - { - 'value': slice( x, null, 2 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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)', 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, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': slice( x, 0, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, 1 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 0 ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerColumns( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( 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 = nditerColumns( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerColumns; - var it1; - var it2; - var x; - var i; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerColumns( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x.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 nditerColumns; - var it; - - nditerColumns = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerColumns( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -});