From 364232973e0310306a8a07c4a0ed5b7a66477705 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 28 Dec 2023 23:07:08 +0000 Subject: [PATCH 01/55] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ab0c939..5d3024d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 3658d2de6b8422de704d39a74346fac752503689 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 28 Dec 2023 23:12:28 +0000 Subject: [PATCH 02/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 68 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 6208 insertions(+), 4915 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e3255c6..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -202,7 +195,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -262,9 +255,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c4d04d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c40463e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cad11bd --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 5ded579..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 5d3024d..16c4c3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Broadcast ndarrays to a common shape.", "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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/ndarray-zeros": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -91,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3801bb5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0375707..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 87e253332b86061c059ad9b3d677c53f74449c71 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 06:36:46 +0000 Subject: [PATCH 03/55] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ab0c939..5d3024d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From cb7b44525fcaafc1b1670fb67d29790c3c22a589 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 06:38:38 +0000 Subject: [PATCH 04/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6339 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cad11bd..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3801bb5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d3d452c0844ab9fed1030ccf667d81662c3ced4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 06:39:14 +0000 Subject: [PATCH 05/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 68 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 6211 insertions(+), 4918 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e3255c6..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -211,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -271,17 +264,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c4d04d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c40463e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cad11bd --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 5ded579..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 5d3024d..16c4c3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Broadcast ndarrays to a common shape.", "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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/ndarray-zeros": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -91,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..40742de --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0375707..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 26db3c3de26cdadc64b21e73ff18212abb74d41b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:29:04 +0000 Subject: [PATCH 06/55] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ab0c939..5d3024d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From c9c99dbbfc38edcd9dc1d0316386cd0c715ff902 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:04:25 +0000 Subject: [PATCH 07/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6339 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cad11bd..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 40742de..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f4b72329f20e086d4c5bf9c76c857b1349b51c6d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:04:57 +0000 Subject: [PATCH 08/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 68 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 6211 insertions(+), 4919 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 92e6e89..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:28:21.415Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e3255c6..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -211,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -271,17 +264,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c4d04d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..571e36d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 5ded579..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 5d3024d..16c4c3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Broadcast ndarrays to a common shape.", "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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/ndarray-zeros": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -91,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5de4217 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0375707..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 9905d5c058e0540b374cbd83e84d0e012c1c33bc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 22:17:00 +0000 Subject: [PATCH 09/55] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ab0c939..5d3024d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From a7e1bf4876b7a51cc46739cdef7b439e72d5da41 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 22:17:24 +0000 Subject: [PATCH 10/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6339 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 571e36d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5de4217..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 378cec4b2a00084899103cf2d0410c776f9abc8f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 22:18:14 +0000 Subject: [PATCH 11/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 68 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 6211 insertions(+), 4918 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e3255c6..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -211,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -271,17 +264,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c4d04d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..571e36d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 5ded579..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 5d3024d..16c4c3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Broadcast ndarrays to a common shape.", "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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/ndarray-zeros": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -91,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f7ee886 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 2c5d7801b315015a75365ad00bd693f767188d22 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 3 Jan 2024 01:43:03 +0000 Subject: [PATCH 12/55] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23f571a..1b615f5 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From c1f00443f4aeda0869b69e554e05da25fd171fd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 3 Jan 2024 01:44:15 +0000 Subject: [PATCH 13/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6339 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 571e36d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f7ee886..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 30e94a0e1f4ad07ad2f82b81f94538a7978bdbd3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 3 Jan 2024 01:44:46 +0000 Subject: [PATCH 14/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 68 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 6211 insertions(+), 4918 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e3255c6..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -211,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -271,17 +264,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c4d04d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..571e36d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 5ded579..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 1b615f5..b3977c5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast ndarrays to a common shape.", "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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/ndarray-zeros": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -91,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cd63db5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From b4bbd8e2fff0753b7ed573f0951693a1db37edd6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 3 Jan 2024 01:45:03 +0000 Subject: [PATCH 15/55] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a5ed7ad..1d12cab 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.1.0-esm/index.mjs'; ``` #### maybeBroadcastArrays( arrays ) @@ -134,7 +134,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.1.0-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From dd5f083c3c6447855f555af614e695fe0ea1c915 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 3 Jan 2024 01:45:04 +0000 Subject: [PATCH 16/55] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d12cab..dce607a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tags). For example, + ```javascript import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.1.0-esm/index.mjs'; ``` @@ -134,7 +139,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.1.0-esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From a51bcd58c148bc1939aedcd8b378573fa13b1278 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 09:06:38 +0000 Subject: [PATCH 17/55] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23f571a..1b615f5 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 7dfbf76b30212be8cbf36ed20fa92c61c9737c06 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:29:33 +0000 Subject: [PATCH 18/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6339 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 571e36d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cd63db5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5768654e2a7d7ebe3ea008f084c19ca06f8236b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:29:58 +0000 Subject: [PATCH 19/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 68 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 6211 insertions(+), 4924 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5007dd2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T06:22:57.305Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e3255c6..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..571e36d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 5ded579..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 1b615f5..b3977c5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast ndarrays to a common shape.", "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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-broadcast-shapes": "^0.1.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/ndarray-zeros": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -91,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e202395 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From fdaa5bcd2c5c0636d225849f0eeb65b2f5ae88aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 01:14:23 +0000 Subject: [PATCH 20/55] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ad5389..609de09 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.0", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.0", "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 4c6eee0201d6aef17427d45c7d0ab8886f73c2b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:48:04 +0000 Subject: [PATCH 21/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6339 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 571e36d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e202395..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c8936711bb639da875d303b3ab20146252b86525 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:48:55 +0000 Subject: [PATCH 22/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 68 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 6211 insertions(+), 4927 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 dbba3b5..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc365d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 5ded579..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 609de09..7dff854 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Broadcast ndarrays to a common shape.", "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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.0", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.0", - "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.0", - "@stdlib/assert-is-array": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/ndarray-zeros": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -91,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..07c3fd0 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From ae0e116387171b97985bb4afe2b7c71c27bb00c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:37:03 +0000 Subject: [PATCH 23/55] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27d9651..f688d6e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.0-esm/index.mjs'; ``` #### maybeBroadcastArrays( arrays ) @@ -134,7 +134,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.0-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 161eae6bb8d7d5ce484dcb318a41d12b552260d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:37:04 +0000 Subject: [PATCH 24/55] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f688d6e..d23990e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tags). For example, + ```javascript import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.0-esm/index.mjs'; ``` @@ -134,7 +139,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.0-esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 1481cfdda4cd84340cf5bdac449bdc772b643280 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:57:53 +0000 Subject: [PATCH 25/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index d8bbc2b..3e2780d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From e86ea72a3ee60238e1dbce546fce0b412fd7e07f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:20:40 +0000 Subject: [PATCH 26/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6339 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc365d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i){var d,m,o,l,h,p,j;if(0===(m=arguments.length))o=[];else if(m>1)for(o=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;ukBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,mGAAoGd,IAFjIG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAG7B,CAFC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,yEAA0EX,EAAMI,IAC7G,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAO,iEAIlB,IADAd,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 07c3fd0..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 67e075b0493ab85f11e63241831ba9b46a283029 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:20:56 +0000 Subject: [PATCH 27/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 4876 insertions(+), 4922 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..187857d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 3e2780d..d0cdfab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-zeros": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/ndarray-ind2sub": "^0.2.0", - "@stdlib/ndarray-zeros": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ac599c1 --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 42a2c97bb4c292146808347c96b3c9973b31e362 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:59:53 +0000 Subject: [PATCH 28/55] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc09418..82f6e6c 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.1-esm/index.mjs'; ``` #### maybeBroadcastArrays( arrays ) @@ -134,7 +134,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.1-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 235b177baa24d031122a060a7d49ba87c91ec1be Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:59:54 +0000 Subject: [PATCH 29/55] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82f6e6c..63da86a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tags). For example, + ```javascript import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.1-esm/index.mjs'; ``` @@ -134,7 +139,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.1-esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 53e2f59b1ff289bd4d5892e3f1c92cc14bee716b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:22:37 +0000 Subject: [PATCH 30/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index 5bc0922..3560a77 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 2a17910e0700bc9ec85b3429ed564a69425bf398 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:08:38 +0000 Subject: [PATCH 31/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 187857d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ac599c1..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b555c471299a7dc542f0408a08224ecc1270bc4c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:08:53 +0000 Subject: [PATCH 32/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 4876 insertions(+), 4924 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index bb65726..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T06:02:19.671Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..651d105 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 3560a77..d0cdfab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-zeros": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..534656f --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From f7e76f0cd2d62331f53f527ff6f37e157d93a07a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:38:27 +0000 Subject: [PATCH 33/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index 5bc0922..3560a77 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From a19bf22da4794391324b96bee70d694c93daeb17 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:09:54 +0000 Subject: [PATCH 34/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 651d105..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 534656f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5707a012b1ff83016cc41d71e678d0ffff988203 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:10:12 +0000 Subject: [PATCH 35/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 4876 insertions(+), 4927 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1aa9f69..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:18:11.157Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..651d105 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 3560a77..d0cdfab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-zeros": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..534656f --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 13e9cc56650378c4d5a4638dfb62d074d79571aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:52:40 +0000 Subject: [PATCH 36/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index 5bc0922..3560a77 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From be16266414c5e29440416a2635e1673e1c1f74cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:16:02 +0000 Subject: [PATCH 37/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 651d105..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 534656f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8b08ddc171fcd75fa28b3d32a11d5ae98f72d0f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:16:22 +0000 Subject: [PATCH 38/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 4876 insertions(+), 4928 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 92c5090..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){ -var h=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-array-like-object/dist'),d=require('@stdlib/ndarray-base-broadcast-shapes/dist'),p=require('@stdlib/ndarray-maybe-broadcast-array/dist'),c=require('@stdlib/ndarray-shape/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..651d105 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 3560a77..d0cdfab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.1", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-zeros": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..534656f --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From f03c2c4287c00c92a4936a15cf91aead2373e2e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:24:57 +0000 Subject: [PATCH 39/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index e059389..54c8b32 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From ecc4cf632d0f91c0bd7757ac27264d50109dc64c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:49:16 +0000 Subject: [PATCH 40/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 651d105..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 534656f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 07dbae9e2e80f6383b9feb307c462d523c0a77c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:49:32 +0000 Subject: [PATCH 41/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 80 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 4876 insertions(+), 5030 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 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 + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ab0feb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){"use strict";var h=require("@stdlib/assert-is-ndarray-like"),g=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/ndarray-base-broadcast-shapes"),p=require("@stdlib/ndarray-maybe-broadcast-array"),c=require("@stdlib/ndarray-shape"),o=require("@stdlib/string-format");function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06c5538 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 54c8b32..409cef5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-zeros": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..569948a --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From d444f59850f70a0169540292818ca6afeef69fbd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:54:20 +0000 Subject: [PATCH 42/55] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4fb55d9..a0dbbd0 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.2-esm/index.mjs'; ``` #### maybeBroadcastArrays( arrays ) @@ -134,7 +134,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.2-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 37798395e6d7f6f6656deff3a83b7e9dc5d808f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:54:21 +0000 Subject: [PATCH 43/55] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0dbbd0..5168a86 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tags). For example, + ```javascript import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.2-esm/index.mjs'; ``` @@ -134,7 +139,7 @@ import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index import zeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@v0.2.2-esm/index.mjs'; +import maybeBroadcastArrays from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-arrays@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 6e196ee29977f68ac9a90850851d88dd2d4aa184 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:29:38 +0000 Subject: [PATCH 44/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index 46d93f7..070b8af 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From ff6f618a057b5e6bc4ad432131dab4c5bb05ecb5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:25:56 +0000 Subject: [PATCH 45/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06c5538..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 569948a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c63b8442548d2cf9143d08d334972acb6d3eae65 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:26:16 +0000 Subject: [PATCH 46/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 78 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 4876 insertions(+), 5029 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7bd20c3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T06:12:09.038Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 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 + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ab0feb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){"use strict";var h=require("@stdlib/assert-is-ndarray-like"),g=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/ndarray-base-broadcast-shapes"),p=require("@stdlib/ndarray-maybe-broadcast-array"),c=require("@stdlib/ndarray-shape"),o=require("@stdlib/string-format");function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..89094d2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index 070b8af..409cef5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-zeros": "^0.3.0", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.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", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aa3f316 --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 3cf152ce9eb228fb12246a9d98e85a0e60d7edbb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:13:58 +0000 Subject: [PATCH 47/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index fc44287..c7a85a7 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From bb90b442cd40be6910a300fb3248a479f3bc4390 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:33:25 +0000 Subject: [PATCH 48/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 89094d2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index aa3f316..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 06df71c08e3235b7c67a1b826e24e51e5b2512f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:33:55 +0000 Subject: [PATCH 49/55] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 80 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 46 files changed, 4876 insertions(+), 5136 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cbce6ea..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-09T02:06:48.358Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 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 + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ab0feb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){"use strict";var h=require("@stdlib/assert-is-ndarray-like"),g=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/ndarray-base-broadcast-shapes"),p=require("@stdlib/ndarray-maybe-broadcast-array"),c=require("@stdlib/ndarray-shape"),o=require("@stdlib/string-format");function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..89094d2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index c7a85a7..409cef5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-zeros": "^0.3.0", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.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", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aa3f316 --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 5fac934afe1a3ef96f31a2f269e2bf777682daac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:38:59 +0000 Subject: [PATCH 50/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index fc44287..c7a85a7 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From ae5c26c62f2d37fb1bcab8f2dcdcebd3a29adf65 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:53:32 +0000 Subject: [PATCH 51/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 89094d2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index aa3f316..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4977682e4aee78978c4193309e05eb5f056bf9c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:54:01 +0000 Subject: [PATCH 52/55] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 80 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 46 files changed, 4876 insertions(+), 5135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 380ef32..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-20T01:36:15.338Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 03f73a5..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/maybe-broadcast-arrays) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 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 + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ab0feb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){"use strict";var h=require("@stdlib/assert-is-ndarray-like"),g=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/ndarray-base-broadcast-shapes"),p=require("@stdlib/ndarray-maybe-broadcast-array"),c=require("@stdlib/ndarray-shape"),o=require("@stdlib/string-format");function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9a7050d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index c7a85a7..409cef5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-zeros": "^0.3.0", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.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", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aa3f316 --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 15a86e35ec34504076f62e924c95e429fad7cb44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 May 2025 00:33:23 +0000 Subject: [PATCH 53/55] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5ded579..4d202c2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -127,7 +127,7 @@ function maybeBroadcastArrays( arrays ) { } else if ( isArrayLikeObject( arrays ) ) { list = arrays; } else { - throw new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) ); + throw new TypeError( format( '1ndFJ', arrays ) ); } N = list.length; @@ -138,13 +138,13 @@ function maybeBroadcastArrays( arrays ) { try { shapes.push( getShape( list[ i ] ) ); } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) ); + throw new TypeError( format( '1ndFK', list[ i ] ) ); } } // Broadcast the shapes to a common shape: sh = broadcastShapes( shapes ); if ( sh === null ) { - throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' ); + throw new Error( format('1ndFH') ); } // Broadcast each array to the common shape... out = []; diff --git a/package.json b/package.json index fc44287..c7a85a7 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 7b3e609b396790f5c548538fc83eebd19e9c4e93 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 May 2025 00:34:41 +0000 Subject: [PATCH 54/55] Remove files --- index.d.ts | 157 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5004 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45677fa..0000000 --- a/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( arrays: ArrayLike> ): Array>; - -/** -* Broadcasts ndarrays to a common shape. -* -* ## Notes -* -* - The function throws an error if a provided broadcast-incompatible ndarrays. -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input array, copy the array before broadcasting. -* -* @param arrays - input arrays -* @throws input arrays must be broadcast compatible -* @returns list of broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( x, y ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArrays( ...arrays: Array> ): Array>; - - -// EXPORTS // - -export = maybeBroadcastArrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9a7050d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index aa3f316..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3fa74dee3348e194b0ae6bf126bb2a0650662467 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 May 2025 00:35:12 +0000 Subject: [PATCH 55/55] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 80 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 205 - benchmark/benchmark.ndims.js | 113 - benchmark/benchmark.num_arrays.js | 125 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 70 - docs/types/test.ts | 105 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 84 - lib/main.js | 160 - package.json | 69 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 46 files changed, 4876 insertions(+), 5139 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 benchmark/benchmark.num_arrays.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 969da13..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-12T00:32:38.841Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b9b5fe3..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/maybe-broadcast-arrays) 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 d320629..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/maybe-broadcast-arrays) 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 ec20c25..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: '50 14 * * 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 + + ```
@@ -213,7 +204,7 @@ for ( i = 0; i < N; i++ ) { ## 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]. @@ -276,17 +267,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-maybe-broadcast-arrays/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays +[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray-broadcast-arrays/tree/esm -[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array +[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray-maybe-broadcast-array/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 6954cfe..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var zeros = require( '@stdlib/ndarray-base-zeros' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, [ 2, 2, 2 ], order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape:num_arrays=2', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var y; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - y = zeros( dtype, shape, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ values[ i%values.length ], y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 2bc0682..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - y = zeros( shape ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( [ x, y ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:num_arrays=2,from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/benchmark/benchmark.num_arrays.js b/benchmark/benchmark.num_arrays.js deleted file mode 100644 index 9886ff5..0000000 --- a/benchmark/benchmark.num_arrays.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArrays = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} narrays - number of arrays to broadcast -* @param {PositiveInteger} ndims - number of dimensions -* @returns {Function} benchmark function -*/ -function createBenchmark( narrays, ndims ) { - var arrays; - var shape; - var sh; - var x; - var y; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - arrays = [ x ]; - for ( i = 1; i < narrays; i++ ) { - if ( i < narrays-1 ) { - y = zeros( sh ); - } else { - y = zeros( shape ); - } - arrays.push( y ); - } - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArrays( arrays ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) { - b.fail( 'should return an array of ndarrays' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 1; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i, 10 ); - bench( pkg+'::ndarray,2d:num_arrays='+i+',from_ndims=2,to_ndims=10', f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 330bfeb..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/maybe-broadcast-arrays" -%% click B href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/maybe-broadcast-arrays -[production-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-maybe-broadcast-arrays/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 f2025b1..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArrays from '../docs/types/index'; -export = maybeBroadcastArrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ab0feb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(t,a){return function(){return a||t((a={exports:{}}).exports,a),a.exports}};var l=m(function(w,v){"use strict";var h=require("@stdlib/assert-is-ndarray-like"),g=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/ndarray-base-broadcast-shapes"),p=require("@stdlib/ndarray-maybe-broadcast-array"),c=require("@stdlib/ndarray-shape"),o=require("@stdlib/string-format");function f(t){var a,s,e,n,i,u,r;if(s=arguments.length,s===0)e=[];else if(s>1)for(e=[],r=0;r} broadcasted arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an ndarray or an array of ndarrays. Value: `%s`.', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( 'invalid argument. An ndarray argument must be an ndarray. Value: `%s`.', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArrays;\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* Broadcast ndarrays to a common shape.\n*\n* @module @stdlib/ndarray-maybe-broadcast-arrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns [ , ]\n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAkB,QAAS,uCAAwC,EACnEC,EAAsB,QAAS,uCAAwC,EACvEC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAgF9C,SAASC,EAAsBC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAL,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,UACGD,EAAQ,EAEnB,IADAC,EAAO,CAAC,EACFI,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCJ,EAAK,KAAM,UAAWI,CAAE,CAAE,UAEhBd,EAAeO,CAAO,EACjCG,EAAO,CAAEH,CAAO,UACLN,EAAmBM,CAAO,EACrCG,EAAOH,MAEP,OAAM,IAAI,UAAWF,EAAQ,mGAAoGE,CAAO,CAAE,EAM3I,IAJAM,EAAIH,EAAK,OAGTF,EAAS,CAAC,EACJM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAI,CACHN,EAAO,KAAMJ,EAAUM,EAAMI,CAAE,CAAE,CAAE,CACpC,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWV,EAAQ,yEAA0EK,EAAMI,CAAE,CAAE,CAAE,CACpH,CAID,GADAF,EAAKV,EAAiBM,CAAO,EACxBI,IAAO,KACX,MAAM,IAAI,MAAO,+DAAgE,EAIlF,IADAD,EAAM,CAAC,EACDG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAI,KAAMR,EAAqBO,EAAMI,CAAE,EAAGF,CAAG,CAAE,EAEhD,OAAOD,CACR,CAKAZ,EAAO,QAAUO,ICjFjB,IAAIU,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "broadcastShapes", "maybeBroadcastArray", "getShape", "format", "maybeBroadcastArrays", "arrays", "shapes", "nargs", "list", "out", "sh", "N", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4553c46..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,70 +0,0 @@ - -{{alias}}( ...arrays ) - Broadcasts ndarrays to a common shape. - - The function supports two (mutually exclusive) means of providing ndarray - arguments: - - 1. Providing a single array containing ndarray arguments. - 2. Providing ndarray arguments as separate arguments. - - If a provided ndarray has a shape matching the common shape, the function - returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - common shape, the function returns a new *read-only* ndarray view of the - provided ndarray's data. The view is typically *not* contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to a view may affect multiple elements. If you need to write to an - input ndarray, copy the input ndarray before broadcasting. - - The function throws an error if a provided broadcast-incompatible ndarrays. - - Parameters - ---------- - arrays: ...ndarray|ArrayLikeObject - Array arguments. - - Returns - ------- - out: Array - Broadcasted arrays. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] ) - - > var out = {{alias}}( [ x, y ] ) - [ , ] - - // Retrieve the broadcasted "x" array: - > var bx = out[ 0 ] - - > sh = bx.shape - [ 3, 2, 2 ] - - // Retrieve broadcasted elements... - > var v = bx.get( 0, 0, 0 ) - 1 - > v = bx.get( 0, 0, 1 ) - 2 - > v = bx.get( 0, 1, 0 ) - 3 - > v = bx.get( 0, 1, 1 ) - 4 - > v = bx.get( 1, 0, 0 ) - 1 - > v = bx.get( 1, 1, 0 ) - 3 - > v = bx.get( 2, 0, 0 ) - 1 - > v = bx.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3663d28..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 maybeBroadcastArrays = require( './index' ); - - -// TESTS // - -// The function returns an array of ndarrays... -{ - const x = zeros( [ 2, 2 ] ); - const y = zeros( [ 2, 2, 2 ] ); - - maybeBroadcastArrays( [ x ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y ] ); // $ExpectType typedndarray[] - maybeBroadcastArrays( [ x, y, x ] ); // $ExpectType typedndarray[] - - maybeBroadcastArrays( x ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y ); // $ExpectType typedndarray[] - maybeBroadcastArrays( x, y, x ); // $ExpectType typedndarray[] -} - -// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays or an ndarray... -{ - maybeBroadcastArrays( '5' ); // $ExpectError - maybeBroadcastArrays( 5 ); // $ExpectError - maybeBroadcastArrays( true ); // $ExpectError - maybeBroadcastArrays( false ); // $ExpectError - maybeBroadcastArrays( null ); // $ExpectError - maybeBroadcastArrays( {} ); // $ExpectError - maybeBroadcastArrays( [ '5' ] ); // $ExpectError - maybeBroadcastArrays( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, '5' ); // $ExpectError - maybeBroadcastArrays( x, 5 ); // $ExpectError - maybeBroadcastArrays( x, true ); // $ExpectError - maybeBroadcastArrays( x, false ); // $ExpectError - maybeBroadcastArrays( x, null ); // $ExpectError - maybeBroadcastArrays( x, {} ); // $ExpectError - maybeBroadcastArrays( x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a third argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fourth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a fifth argument which is an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - - maybeBroadcastArrays( x, x, x, x, '5' ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, 5 ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, true ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, false ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, null ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, {} ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, [ '5' ] ); // $ExpectError - maybeBroadcastArrays( x, x, x, x, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 2d250f1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArrays = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Create a 3x2x2 array: -var y = zeros( [ 3, 2, 2 ] ); -// returns - -// Broadcast arrays to a common shape: -var out = maybeBroadcastArrays( [ x, y ] ); -// returns - -// Retrieve the common shape: -var sh = out[ 0 ].shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'X[%s] = %d', ind2sub( sh, i ).join( ', ' ), out[ 0 ].iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3d99ee..45677fa 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9a7050d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-maybe-broadcast-array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i){var o,m,a,h,l,p,j;if(0===(m=arguments.length))a=[];else if(m>1)for(a=[],j=0;j} broadcasted arrays\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x1.shape;\n* // returns [ 2, 2 ]\n*\n* var y1 = zeros( [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y1.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var out = maybeBroadcastArrays( [ x1, y1 ] );\n* // returns \n*\n* var x2 = out[ 0 ];\n* // returns \n*\n* var y2 = out[ 1 ];\n* // returns \n*\n* shx = x2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* shy = y2.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = x2.get( 0, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 0, 0, 1 );\n* // returns 2\n*\n* v = x2.get( 1, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 1, 1, 0 );\n* // returns 3\n*\n* v = x2.get( 2, 0, 0 );\n* // returns 1\n*\n* v = x2.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns \n*\n* var y = zeros( [ 4, 2 ] );\n* // returns \n*\n* var out = maybeBroadcastArrays( [ x, y ] );\n* // throws \n*/\nfunction maybeBroadcastArrays( arrays ) {\n\tvar shapes;\n\tvar nargs;\n\tvar list;\n\tvar out;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tlist = [];\n\t} else if ( nargs > 1 ) {\n\t\tlist = [];\n\t\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\t\tlist.push( arguments[ i ] );\n\t\t}\n\t} else if ( isndarrayLike( arrays ) ) {\n\t\tlist = [ arrays ];\n\t} else if ( isArrayLikeObject( arrays ) ) {\n\t\tlist = arrays;\n\t} else {\n\t\tthrow new TypeError( format( '1ndFJ', arrays ) );\n\t}\n\tN = list.length;\n\n\t// Resolve the list of shapes...\n\tshapes = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\t// Delegate input argument validation to `getShape`...\n\t\ttry {\n\t\t\tshapes.push( getShape( list[ i ] ) );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\tthrow new TypeError( format( '1ndFK', list[ i ] ) );\n\t\t}\n\t}\n\t// Broadcast the shapes to a common shape:\n\tsh = broadcastShapes( shapes );\n\tif ( sh === null ) {\n\t\tthrow new Error( format('1ndFH') );\n\t}\n\t// Broadcast each array to the common shape...\n\tout = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( maybeBroadcastArray( list[ i ], sh ) );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArrays;\n"],"names":["maybeBroadcastArrays","arrays","shapes","nargs","list","out","sh","N","i","arguments","length","push","isndarrayLike","isArrayLikeObject","TypeError","format","getShape","err","broadcastShapes","Error","maybeBroadcastArray"],"mappings":";;glBA2GA,SAASA,EAAsBC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAe,KADfL,EAAQM,UAAUC,QAEjBN,EAAO,QACD,GAAKD,EAAQ,EAEnB,IADAC,EAAO,GACDI,EAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAClCJ,EAAKO,KAAMF,UAAWD,SAEjB,GAAKI,EAAeX,GAC1BG,EAAO,CAAEH,OACH,KAAKY,EAAmBZ,GAG9B,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCG,EAAOH,CAGP,CAKD,IAJAM,EAAIH,EAAKM,OAGTR,EAAS,GACHM,EAAI,EAAGA,EAAID,EAAGC,IAEnB,IACCN,EAAOS,KAAMK,EAAUZ,EAAMI,IAC7B,CAAC,MAAQS,GACT,MAAM,IAAIH,UAAWC,EAAQ,QAASX,EAAMI,IAC5C,CAIF,GAAY,QADZF,EAAKY,EAAiBhB,IAErB,MAAM,IAAIiB,MAAOJ,EAAO,UAIzB,IADAV,EAAM,GACAG,EAAI,EAAGA,EAAID,EAAGC,IACnBH,EAAIM,KAAMS,EAAqBhB,EAAMI,GAAKF,IAE3C,OAAOD,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8a043c9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast ndarrays to a common shape. -* -* @module @stdlib/ndarray-maybe-broadcast-arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* var maybeBroadcastArrays = require( '@stdlib/ndarray-maybe-broadcast-arrays' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns [ , ] -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 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 4d202c2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarrays to a common shape. -* -* ## Notes -* -* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new **read-only** ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to an input ndarray, copy the input ndarray before broadcasting. -* -* @param {...ndarray} arrays - ndarray arguments -* @throws {TypeError} first argument must be an ndarray or an array of ndarrays -* @throws {TypeError} must provide valid ndarray arguments -* @throws {Error} input arrays must be broadcast compatible -* @returns {Array} broadcasted arrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x1.shape; -* // returns [ 2, 2 ] -* -* var y1 = zeros( [ 3, 2, 2 ] ); -* // returns -* -* var shy = y1.shape; -* // returns [ 3, 2, 2 ] -* -* var out = maybeBroadcastArrays( [ x1, y1 ] ); -* // returns -* -* var x2 = out[ 0 ]; -* // returns -* -* var y2 = out[ 1 ]; -* // returns -* -* shx = x2.shape; -* // returns [ 3, 2, 2 ] -* -* shy = y2.shape; -* // returns [ 3, 2, 2 ] -* -* var v = x2.get( 0, 0, 0 ); -* // returns 1 -* -* v = x2.get( 0, 0, 1 ); -* // returns 2 -* -* v = x2.get( 1, 0, 0 ); -* // returns 1 -* -* v = x2.get( 1, 1, 0 ); -* // returns 3 -* -* v = x2.get( 2, 0, 0 ); -* // returns 1 -* -* v = x2.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var x = zeros( [ 2, 2 ] ); -* // returns -* -* var y = zeros( [ 4, 2 ] ); -* // returns -* -* var out = maybeBroadcastArrays( [ x, y ] ); -* // throws -*/ -function maybeBroadcastArrays( arrays ) { - var shapes; - var nargs; - var list; - var out; - var sh; - var N; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - list = []; - } else if ( nargs > 1 ) { - list = []; - for ( i = 0; i < arguments.length; i++ ) { - list.push( arguments[ i ] ); - } - } else if ( isndarrayLike( arrays ) ) { - list = [ arrays ]; - } else if ( isArrayLikeObject( arrays ) ) { - list = arrays; - } else { - throw new TypeError( format( '1ndFJ', arrays ) ); - } - N = list.length; - - // Resolve the list of shapes... - shapes = []; - for ( i = 0; i < N; i++ ) { - // Delegate input argument validation to `getShape`... - try { - shapes.push( getShape( list[ i ] ) ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( '1ndFK', list[ i ] ) ); - } - } - // Broadcast the shapes to a common shape: - sh = broadcastShapes( shapes ); - if ( sh === null ) { - throw new Error( format('1ndFH') ); - } - // Broadcast each array to the common shape... - out = []; - for ( i = 0; i < N; i++ ) { - out.push( maybeBroadcastArray( list[ i ], sh ) ); - } - return out; -} - - -// EXPORTS // - -module.exports = maybeBroadcastArrays; diff --git a/package.json b/package.json index c7a85a7..409cef5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast ndarrays to a common shape.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-broadcast-shapes": "^0.2.2", - "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-zeros": "^0.3.0", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.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", @@ -92,7 +28,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aa3f316 --- /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 c43dc3b..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var maybeBroadcastArrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArrays, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray or an array-like object containing ndarrays', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not an ndarray', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ '5' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( x, x, x, x, value ); - }; - } -}); - -tape( 'the function throws an error if provided broadcast-incompatible ndarrays', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 20 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 5, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArrays( [ x, zeros( value ) ] ); - }; - } -}); - -tape( 'the function returns an empty array if provided an empty array', function test( t ) { - var out = maybeBroadcastArrays( [] ); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an empty array if not provided any arguments', function test( t ) { - var out = maybeBroadcastArrays(); - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.deepEqual( out, [], 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, list)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( [ x ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (1 array, argument)', function test( t ) { - var out; - var x; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - out = maybeBroadcastArrays( x ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 0 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, list)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( [ x, y ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - out = maybeBroadcastArrays( x, y ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, list)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns ndarray instances (>2 arrays, arguments)', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( x, y, z ); - - t.strictEqual( isArray( out ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - - t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 0 ] ), true, 'returns expected value' ); - - t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - t.strictEqual( isReadOnly( out[ 1 ] ), false, 'returns expected value' ); - - t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); - t.strictEqual( isReadOnly( out[ 2 ] ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns views over underlying array data buffers', function test( t ) { - var out; - var x; - var y; - var z; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = zeros( [ 2, 2, 2 ] ); - z = zeros( [ 1 ] ); - out = maybeBroadcastArrays( [ x, y, z ] ); - - t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' ); - t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' ); - t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' ); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (column-major)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - y = zeros( [ 5, 1, 2 ], { - 'order': 'row-major', - 'dtype': 'generic' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same shape)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 2, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - // Should return the same instance: - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - y = zeros( [ 1, 2, 1 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) { - var expected; - var data; - var out; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - y = zeros( [ 5, 2, 2 ], { - 'dtype': 'generic', - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - out = maybeBroadcastArrays( [ x, y ] ); - - t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' ); - t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = out[ 0 ].get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = out[ 0 ].get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = out[ 0 ].get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = out[ 0 ].get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -});