diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2319d94..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-21T00:30:35.822Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6818db8..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 569e099..4225c36 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3c421dc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d3f2c26..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index d42071a..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -});