From 8e4b3e4e6b84a9beaafdcfc79383472338ccd604 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 16 Jun 2024 23:27:42 +0000 Subject: [PATCH 01/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index d580bd3..8e2f79a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 3b7d5f5..641c05b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-resolve-getter": "^0.2.1", "@stdlib/array-base-resolve-setter": "^0.2.1", "@stdlib/ndarray-base-ind": "^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 fea20589fc3367d4bbb02eb5b7af272595cdd29d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 16 Jun 2024 23:28:24 +0000 Subject: [PATCH 02/65] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 53 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 114 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 421 -- 43 files changed, 4868 insertions(+), 4388 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 f92a6c5..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 + + ```
@@ -170,7 +161,7 @@ console.log( out ); ## 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]. @@ -233,9 +224,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0c75117..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=c(function(A,f){ -var d=require('@stdlib/array-base-resolve-getter/dist'),q=require('@stdlib/array-base-resolve-setter/dist'),b=require('@stdlib/ndarray-base-ind/dist').factory,w=require('@stdlib/error-tools-fmtprodmsg/dist');function x(e,r,t,p){var o,h,s,g,u,v,n,a,i,m;if(h=q(e),s=d(r),g=d(t),o=b(p),u=e.length-1,a=r.length,a>0)if(t.length===a)v=1;else if(t.length===1)v=0;else throw new Error(w("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",t.length,a));for(n=0,i=0;i 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === N ) {\n\t\t\tvs = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tvs = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, N ) );\n\t\t}\n\t}\n\tvo = 0;\n\n\t// Replace each desired element in the provided array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tj = getIndex( iget( indices, i ), max );\n\t\txset( x, j, vget( values, vo ) );\n\t\tvo += vs;\n\t}\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,mCAAoC,EAC7DC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EAuC9C,SAASC,EAAKC,EAAGC,EAASC,EAAQC,EAAO,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EAeJ,GAZAP,EAAOT,EAAeI,CAAE,EACxBM,EAAOX,EAAeM,CAAQ,EAC9BM,EAAOZ,EAAeO,CAAO,EAG7BE,EAAWP,EAAKM,CAAK,EAGrBK,EAAMR,EAAE,OAAS,EAGjBW,EAAIV,EAAQ,OACPU,EAAI,EAER,GAAKT,EAAO,SAAWS,EACtBF,EAAK,UACMP,EAAO,SAAW,EAC7BO,EAAK,MAEL,OAAM,IAAI,MAAOX,EAAQ,sIAAuII,EAAO,OAAQS,CAAE,CAAE,EAMrL,IAHAD,EAAK,EAGC,EAAI,EAAG,EAAIC,EAAG,IACnBC,EAAIR,EAAUE,EAAML,EAAS,CAAE,EAAGO,CAAI,EACtCH,EAAML,EAAGY,EAAGL,EAAML,EAAQQ,CAAG,CAAE,EAC/BA,GAAMD,EAEP,OAAOT,CACR,CAKAN,EAAO,QAAUK,ICvEjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "resolveGetter", "resolveSetter", "ind", "format", "put", "x", "indices", "values", "mode", "getIndex", "xset", "iget", "vget", "max", "vs", "vo", "N", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 411e094..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: Array - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index dd26de2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5550b5d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import{factory as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,d,i,m){var a,o,h,l,g,p,j,v,f;if(o=t(n),h=e(d),l=e(i),a=r(m),g=n.length-1,(v=d.length)>0)if(i.length===v)p=1;else{if(1!==i.length)throw new Error(s("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",i.length,v));p=0}for(j=0,f=0;f 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === N ) {\n\t\t\tvs = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tvs = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, N ) );\n\t\t}\n\t}\n\tvo = 0;\n\n\t// Replace each desired element in the provided array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tj = getIndex( iget( indices, i ), max );\n\t\txset( x, j, vget( values, vo ) );\n\t\tvo += vs;\n\t}\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","xset","iget","vget","max","vs","vo","N","i","resolveSetter","resolveGetter","ind","length","Error","format"],"mappings":";;+YAgEA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAgBJ,GAZAP,EAAOQ,EAAeb,GACtBM,EAAOQ,EAAeb,GACtBM,EAAOO,EAAeZ,GAGtBE,EAAWW,EAAKZ,GAGhBK,EAAMR,EAAEgB,OAAS,GAGjBL,EAAIV,EAAQe,QACH,EAER,GAAKd,EAAOc,SAAWL,EACtBF,EAAK,MACC,IAAuB,IAAlBP,EAAOc,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIhB,EAAOc,OAAQL,IAF/KF,EAAK,CAGL,CAKF,IAHAC,EAAK,EAGCE,EAAI,EAAGA,EAAID,EAAGC,IAEnBP,EAAML,EADFI,EAAUE,EAAML,EAASW,GAAKJ,GACtBD,EAAML,EAAQQ,IAC1BA,GAAMD,EAEP,OAAOT,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 8e2f79a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Array} output array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var xset; - var iget; - var vget; - var max; - var vs; - var vo; - var N; - var i; - var j; - - // Resolve accessors for accessing array elements: - xset = resolveSetter( x ); - iget = resolveGetter( indices ); - vget = resolveGetter( values ); - - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - // Broadcast the `values` array... - N = indices.length; - if ( N > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === N ) { - vs = 1; - } else if ( values.length === 1 ) { - vs = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, N ) ); - } - } - vo = 0; - - // Replace each desired element in the provided array... - for ( i = 0; i < N; i++ ) { - j = getIndex( iget( indices, i ), max ); - xset( x, j, vget( values, vo ) ); - vo += vs; - } - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 641c05b..8217263 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/ndarray-base-ind": "^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-base-filled-by": "^0.2.1", - "@stdlib/array-base-linspace": "^0.2.1", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-complex64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4835321 --- /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 18865ec..0000000 --- a/test/test.js +++ /dev/null @@ -1,421 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 16d4772bc5cf3bdb4393773421c02f273ab28434 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Jun 2024 04:22:50 +0000 Subject: [PATCH 03/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3f3433b..10cf363 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 1f15034..316f424 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.1", "@stdlib/strided-base-reinterpret-boolean": "github:stdlib-js/strided-base-reinterpret-boolean#main", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 816152e5ab5a5316d7ee1287d4ab8246d6e1a6a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Jun 2024 04:23:14 +0000 Subject: [PATCH 04/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5550b5d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import{factory as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,d,i,m){var a,o,h,l,g,p,j,v,f;if(o=t(n),h=e(d),l=e(i),a=r(m),g=n.length-1,(v=d.length)>0)if(i.length===v)p=1;else{if(1!==i.length)throw new Error(s("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",i.length,v));p=0}for(j=0,f=0;f 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === N ) {\n\t\t\tvs = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tvs = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, N ) );\n\t\t}\n\t}\n\tvo = 0;\n\n\t// Replace each desired element in the provided array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tj = getIndex( iget( indices, i ), max );\n\t\txset( x, j, vget( values, vo ) );\n\t\tvo += vs;\n\t}\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","xset","iget","vget","max","vs","vo","N","i","resolveSetter","resolveGetter","ind","length","Error","format"],"mappings":";;+YAgEA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAgBJ,GAZAP,EAAOQ,EAAeb,GACtBM,EAAOQ,EAAeb,GACtBM,EAAOO,EAAeZ,GAGtBE,EAAWW,EAAKZ,GAGhBK,EAAMR,EAAEgB,OAAS,GAGjBL,EAAIV,EAAQe,QACH,EAER,GAAKd,EAAOc,SAAWL,EACtBF,EAAK,MACC,IAAuB,IAAlBP,EAAOc,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIhB,EAAOc,OAAQL,IAF/KF,EAAK,CAGL,CAKF,IAHAC,EAAK,EAGCE,EAAI,EAAGA,EAAID,EAAGC,IAEnBP,EAAML,EADFI,EAAUE,EAAML,EAASW,GAAKJ,GACtBD,EAAML,EAAQQ,IAC1BA,GAAMD,EAEP,OAAOT,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4835321..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3fc6f852ed6542c8f6387d2af89b04418bf00d40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Jun 2024 04:24:07 +0000 Subject: [PATCH 05/65] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 55 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4706 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 f92a6c5..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 + + ```
@@ -170,7 +161,7 @@ console.log( out ); ## 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]. @@ -233,9 +224,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ea475b4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 460774a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 411e094..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: Array - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index dd26de2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7602222 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;suBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 10cf363..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 316f424..8217263 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "github:stdlib-js/array-base-assert-is-boolean-data-type#main", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.1", - "@stdlib/strided-base-reinterpret-boolean": "github:stdlib-js/strided-base-reinterpret-boolean#main", - "@stdlib/strided-base-reinterpret-complex": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.1", - "@stdlib/array-base-linspace": "^0.2.1", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "github:stdlib-js/array-bool#main", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-complex64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01947bc --- /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 f0a7e42..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 19f6c3180fe59c471a7d56bddc8591446819d8eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Jun 2024 07:08:47 +0000 Subject: [PATCH 06/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3f3433b..10cf363 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 1f15034..316f424 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.1", "@stdlib/strided-base-reinterpret-boolean": "github:stdlib-js/strided-base-reinterpret-boolean#main", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 456c7a0aba2baeb6381915e07e28aff82e7e343f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Jun 2024 07:09:13 +0000 Subject: [PATCH 07/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7602222..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;suBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 01947bc..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 12f197e9437da41bcf8a92c5e19f9f3789eb5d0c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Jun 2024 07:09:48 +0000 Subject: [PATCH 08/65] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 59 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4714 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 f92a6c5..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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ea475b4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 460774a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index dd26de2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7602222 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;suBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 10cf363..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 316f424..8217263 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "github:stdlib-js/array-base-assert-is-boolean-data-type#main", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.1", - "@stdlib/strided-base-reinterpret-boolean": "github:stdlib-js/strided-base-reinterpret-boolean#main", - "@stdlib/strided-base-reinterpret-complex": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.1", - "@stdlib/array-base-linspace": "^0.2.1", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "github:stdlib-js/array-bool#main", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-complex64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01947bc --- /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 c96d2b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 30af489f48afbcb0b5c89e4845770631f55def95 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Jun 2024 16:23:37 +0000 Subject: [PATCH 09/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3f3433b..10cf363 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 36d638e..e3393e2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.1", "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 adb2528c951805152c1cb638adb58aac7a7eb7f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Jun 2024 16:24:22 +0000 Subject: [PATCH 10/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7602222..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;suBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 01947bc..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6b2a4c7913d69ac66e4eae0ad8f18eb2a9ca729d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Jun 2024 16:24:45 +0000 Subject: [PATCH 11/65] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 59 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4714 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 f92a6c5..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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ea475b4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 460774a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index dd26de2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1b1f79d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;6uBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 10cf363..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index e3393e2..3787491 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "github:stdlib-js/array-base-assert-is-boolean-data-type#main", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.1", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", - "@stdlib/strided-base-reinterpret-complex": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.1", - "@stdlib/array-base-linspace": "^0.2.1", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-complex64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b95f02f --- /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 c96d2b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From e8bf90baef1397450347a00295da8d25d1299e41 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Jun 2024 16:25:05 +0000 Subject: [PATCH 12/65] Update README.md for ESM bundle v0.0.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 50b13fc..a0759fe 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.1-esm/index.mjs'; ``` #### put( x, indices, values, mode ) @@ -117,7 +117,7 @@ var bool = ( out === x ); import filledBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs'; import discreteUniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@esm/index.mjs'; import linspace from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs'; -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.1-esm/index.mjs'; // Generate a linearly spaced array: var x = linspace( 0, 100, 11 ); From 9fc8553926ec719cfaabce538f6f549ad768cbc4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Jun 2024 16:25:06 +0000 Subject: [PATCH 13/65] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0759fe..33558cf 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ limitations under the License. ## Usage +```javascript +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@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/array-base-put/tags). For example, + ```javascript import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.1-esm/index.mjs'; ``` @@ -117,7 +122,7 @@ var bool = ( out === x ); import filledBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs'; import discreteUniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@esm/index.mjs'; import linspace from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs'; -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.1-esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; // Generate a linearly spaced array: var x = linspace( 0, 100, 11 ); From 75980aa5638503b987438ef9b9b4eafc74d08dd9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Jun 2024 01:55:47 +0000 Subject: [PATCH 14/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 638de4c..21a2927 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.1", "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 2fe85607fd6ccf6eea5f3f05c1070b73368f38f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Jun 2024 01:56:13 +0000 Subject: [PATCH 15/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1b1f79d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, [ 30 ], 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;6uBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b95f02f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6dec9554a8362858f3b433fd43efaff1e288f318 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Jun 2024 01:56:33 +0000 Subject: [PATCH 16/65] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 93 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4748 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 f92a6c5..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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ea475b4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index dd26de2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..304b58a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 21a2927..3787491 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.1", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", - "@stdlib/strided-base-reinterpret-complex": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.1", - "@stdlib/array-base-linspace": "^0.2.1", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-complex64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..201ee58 --- /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 c96d2b3..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 2114f9fe80dfe03e77e3a64b30f119250a4ea3fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 03:27:20 +0000 Subject: [PATCH 17/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index e3eb619..716c32d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.1", "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 8d075fd30efd18ff3f839007ff1c3b8e124912ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 03:38:08 +0000 Subject: [PATCH 18/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 304b58a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 201ee58..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9ee428aeac1071dc866674b879b382076d76e60a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 03:38:27 +0000 Subject: [PATCH 19/65] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 95 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4750 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 f92a6c5..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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index dd26de2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..304b58a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 716c32d..3787491 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.1", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", - "@stdlib/strided-base-reinterpret-complex": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.1", - "@stdlib/array-base-linspace": "^0.2.1", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-complex64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float32-imag": "github:stdlib-js/complex-float32-imag#main", - "@stdlib/complex-float32-real": "github:stdlib-js/complex-float32-real#main", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..201ee58 --- /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 66caf0f..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 95e4e0fd0669fb594c7a716e8279be511ad85b14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 18 Jul 2024 03:53:11 +0000 Subject: [PATCH 20/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 03ccfb2..9738b01 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.1", "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 d23f3f4d6544714f6064a481f91edd1550736e8d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 18 Jul 2024 03:53:55 +0000 Subject: [PATCH 21/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 304b58a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 201ee58..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 561a9a192093bdb4675fa97de7031a8fb92b1b35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 18 Jul 2024 03:54:13 +0000 Subject: [PATCH 22/65] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 96 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4751 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 f92a6c5..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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 94e31f4..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..304b58a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 9738b01..3787491 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.1", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", - "@stdlib/strided-base-reinterpret-complex": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.1", - "@stdlib/array-base-linspace": "^0.2.1", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-complex64": "^0.2.1", - "@stdlib/complex-float32-ctor": "^0.0.1", - "@stdlib/complex-float32-imag": "^0.1.0", - "@stdlib/complex-float32-real": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..201ee58 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From b2edfb166e8bc3ce970a2cab27f4237e869cb0f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 11:55:42 +0000 Subject: [PATCH 23/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 93e2dd9..b6af918 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.2", "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 a72821a57d8f21646b5f340d0fac24e208d21423 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 12:00:55 +0000 Subject: [PATCH 24/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 304b58a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 201ee58..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b997b523f5fa4c54ea8d6f04884892fdb3874a47 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 12:01:15 +0000 Subject: [PATCH 25/65] 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 | 96 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4753 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 94e31f4..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [], ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..80b7f4f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index b6af918..d289dab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.2", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex": "^0.1.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-linspace": "^0.2.2", - "@stdlib/array-base-to-accessor-array": "^0.2.1", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-complex64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e5cea4f --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From f2dc2cc88ce4300d8d2a0f021f6824985fd4cc22 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 12:03:51 +0000 Subject: [PATCH 26/65] Update README.md for ESM bundle v0.0.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 93309f7..c667b12 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.2-esm/index.mjs'; ``` #### put( x, indices, values, mode ) @@ -117,7 +117,7 @@ var bool = ( out === x ); import filledBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs'; import discreteUniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@esm/index.mjs'; import linspace from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs'; -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.2-esm/index.mjs'; // Generate a linearly spaced array: var x = linspace( 0, 100, 11 ); From f26ba16524c6dad7324cd9a7f7fe2c99b7961fe8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 12:03:52 +0000 Subject: [PATCH 27/65] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c667b12..07965e7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ limitations under the License. ## Usage +```javascript +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@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/array-base-put/tags). For example, + ```javascript import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.2-esm/index.mjs'; ``` @@ -117,7 +122,7 @@ var bool = ( out === x ); import filledBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs'; import discreteUniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@esm/index.mjs'; import linspace from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs'; -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.2-esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; // Generate a linearly spaced array: var x = linspace( 0, 100, 11 ); From 2144928dd0314607ef97330472d703760411c8fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Sep 2024 02:43:12 +0000 Subject: [PATCH 28/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 998e491..e4d5264 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.2", "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", "@stdlib/strided-base-reinterpret-complex": "^0.1.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 0dac21bb845a6d896adad312b45fad23962efb7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Sep 2024 02:48:43 +0000 Subject: [PATCH 29/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 80b7f4f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e5cea4f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 51477b8c275e8db46fdcc86f30da28fecb69adf2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Sep 2024 02:49:05 +0000 Subject: [PATCH 30/65] 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 | 130 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 --- 43 files changed, 4868 insertions(+), 4787 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.length.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 53172b7..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..80b7f4f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index e4d5264..d289dab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.2", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex": "^0.1.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-linspace": "^0.2.2", - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-complex64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e5cea4f --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From a6b7b424d0f3aaa7da21693f02c00288439c7d64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 00:59:18 +0000 Subject: [PATCH 31/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 294b97b..4ddc2b2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.2", "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 354842021bddab1f691a42ecc19d2054fcea48cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:19:43 +0000 Subject: [PATCH 32/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 80b7f4f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e5cea4f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 69de2d0110afa84d46b992e796c5d90f36c29808 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:20:03 +0000 Subject: [PATCH 33/65] 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 | 130 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 45 files changed, 4868 insertions(+), 4896 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.length.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 1f6d6bd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-07T00:57:36.874Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 dadf180..97c7164 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9003a76 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 4ddc2b2..d289dab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.2", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex": "^0.1.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-linspace": "^0.2.2", - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-complex64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e5cea4f --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From fb8245c8ee0f534936c2e6cfe504a93e5982d24b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 25 Jun 2025 12:32:11 +0000 Subject: [PATCH 34/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 294b97b..4ddc2b2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.2", "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 0dad9f38ae84463c0ab92ad028210e8f56dd2ec8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 25 Jun 2025 12:32:37 +0000 Subject: [PATCH 35/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 97c7164..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9003a76..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e5cea4f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 82592767856700221e4d2589194aa076c2de1dd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 25 Jun 2025 12:33:05 +0000 Subject: [PATCH 36/65] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 44 files changed, 4868 insertions(+), 4896 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9003a76 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 4ddc2b2..d289dab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.2", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex": "^0.1.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-linspace": "^0.2.2", - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-complex64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e5cea4f --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From fe7d47e9f267053d200f76467d812acebb4cfd61 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 06:38:34 +0000 Subject: [PATCH 37/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 2a84d3f..b0adb8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.2", "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", "@stdlib/strided-base-reinterpret-complex": "^0.1.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 59959eb6cc3bb01ef9db53f5aa60e37ef3a5278c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:42:32 +0000 Subject: [PATCH 38/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9003a76..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e5cea4f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From be77d75c2c41315851a9d986f2ea04e150c193f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:42:48 +0000 Subject: [PATCH 39/65] Auto-generated commit --- .editorconfig | 180 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 44 files changed, 4868 insertions(+), 5001 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..fc4286e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index b0adb8b..d289dab 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.2", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ind": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex": "^0.1.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-linspace": "^0.2.2", - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-bool": "^0.1.1", - "@stdlib/array-complex64": "^0.3.1", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-complex64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.1.0", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/random-array-discrete-uniform": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^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", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e5cea4f --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 48854b388404c49bc7c0d04236c797ee2f20cef4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:03:32 +0000 Subject: [PATCH 40/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index 2715ba4..1ffafbc 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From e7f2ed3e8b2b7c90b88fdf9a04cd2010071e157e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:52:09 +0000 Subject: [PATCH 41/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index fc4286e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@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 d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e5cea4f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e13bf5d519891a1947aa09584e889997de8af19e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:52:26 +0000 Subject: [PATCH 42/65] Auto-generated commit --- .editorconfig | 180 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 44 files changed, 4868 insertions(+), 4994 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 1ffafbc..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 669930e276d6752619734ebde298a5104fc662b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:16:36 +0000 Subject: [PATCH 43/65] Update README.md for ESM bundle v0.0.3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ca3b4ac..93260c7 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.3-esm/index.mjs'; ``` #### put( x, indices, values, mode ) @@ -117,7 +117,7 @@ var bool = ( out === x ); import filledBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs'; import discreteUniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@esm/index.mjs'; import linspace from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs'; -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.3-esm/index.mjs'; // Generate a linearly spaced array: var x = linspace( 0, 100, 11 ); From bb645538e9dadbe0180444e2605f26d472708a20 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:16:37 +0000 Subject: [PATCH 44/65] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93260c7..bec91a1 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ limitations under the License. ## Usage +```javascript +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@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/array-base-put/tags). For example, + ```javascript import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.3-esm/index.mjs'; ``` @@ -117,7 +122,7 @@ var bool = ( out === x ); import filledBy from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs'; import discreteUniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@esm/index.mjs'; import linspace from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs'; -import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@v0.0.3-esm/index.mjs'; +import put from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-put@esm/index.mjs'; // Generate a linearly spaced array: var x = linspace( 0, 100, 11 ); From a193455bf212d908b78403940d84d0b1dbb56e55 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Mar 2026 00:47:24 +0000 Subject: [PATCH 45/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index b607558..f941295 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From b49a6dab1003bd5f2c0be78b2ea4b890fe5f9dc7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Mar 2026 01:05:07 +0000 Subject: [PATCH 46/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a7248d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a47c659..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5c9ff7f5bd72ee4e39ff1036b4e6f7ac21393d78 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Mar 2026 01:05:36 +0000 Subject: [PATCH 47/65] 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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 45 files changed, 4868 insertions(+), 4995 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.length.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 88a793e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-03-02T00:45:21.868Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index f941295..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 23771ec6a721496381b33e16527a86f22919a694 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Apr 2026 03:31:12 +0000 Subject: [PATCH 48/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index b607558..f941295 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 74fa8151287385aa78c5d03dbfd081d9b19536c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Apr 2026 03:53:45 +0000 Subject: [PATCH 49/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a7248d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a47c659..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c2fde7a83591305517bbe01705ed6fe9f7310b83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Apr 2026 03:54:08 +0000 Subject: [PATCH 50/65] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 78 - benchmark/benchmark.length.js | 113 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 45 files changed, 4868 insertions(+), 5006 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.length.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8098102..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-09T03:27:29.863Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 7969421..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::broadcasting:len=100', function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index a873249..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index f941295..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From fc1ec033ed7822e74678c827b6734040161511f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 21 Apr 2026 00:31:43 +0000 Subject: [PATCH 51/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index b607558..f941295 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From babc15304e8d8ef825d5d8df7945f57698e599c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 21 Apr 2026 00:37:03 +0000 Subject: [PATCH 52/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a7248d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a47c659..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8300cb903edcaff4eaa7a346ab6b8e18ccc8fae9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 21 Apr 2026 00:37:29 +0000 Subject: [PATCH 53/65] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 165 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 79 - benchmark/benchmark.length.js | 114 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 44 files changed, 4868 insertions(+), 5041 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 085038b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::no_broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index 3ee8520..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index f941295..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From e43e109dedb64d3e765371504763708614321f9d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 17 May 2026 03:35:59 +0000 Subject: [PATCH 54/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index b607558..f941295 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From e3e9487afd4eaf5a9e062b1b5d828d4e58a56faf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 17 May 2026 03:51:18 +0000 Subject: [PATCH 55/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a7248d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a47c659..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b7c1c5ae121155a032bda21b82b401a9ea65e734 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 17 May 2026 03:51:36 +0000 Subject: [PATCH 56/65] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 165 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 79 - benchmark/benchmark.length.js | 114 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 45 files changed, 4868 insertions(+), 5047 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.length.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0cbf33a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-17T03:32:05.573Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 085038b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::no_broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index 3ee8520..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index f941295..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 703a90ffe2c386cdad8d039ab7f951f94041cb8f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 03:45:14 +0000 Subject: [PATCH 57/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index b607558..f941295 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 861df16636fa6a370059503d10165a8d31dd708c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 04:04:20 +0000 Subject: [PATCH 58/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a7248d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a47c659..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 69b285135d28adb5f9ab3d41c353fafb1443c56d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 04:04:41 +0000 Subject: [PATCH 59/65] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 165 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 79 - benchmark/benchmark.length.js | 114 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 45 files changed, 4868 insertions(+), 5060 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.length.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c85fc4f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-20T03:31:27.749Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 085038b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::no_broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index 3ee8520..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 07dc6d2..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5da802a..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\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,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index f941295..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 1eb65c727245a63505f7d4e68bd6ee7e8362651e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 30 Jun 2026 03:47:21 +0000 Subject: [PATCH 60/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index c8ebc89..91123ce 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 49bb019c9266ddb1f67b9ad357334abc7a47d5b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 30 Jun 2026 04:01:25 +0000 Subject: [PATCH 61/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a7248d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a47c659..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5233585b888a3c8359e28ec1e2702bc08e5704ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 30 Jun 2026 04:01:46 +0000 Subject: [PATCH 62/65] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 165 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 79 - benchmark/benchmark.length.js | 114 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 45 files changed, 4868 insertions(+), 5060 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.length.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 465ae17..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-06-30T03:35:43.056Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 085038b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::no_broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index 3ee8520..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 699c595..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){try{return a||r((a={exports:{}}).exports,a),a.exports}catch(v){throw (a=0, v)}};};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 87297b5..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 91123ce..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 9c673b8fb6451b39ee3c5748fdd608f5681bee33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Aug 2026 03:08:25 +0000 Subject: [PATCH 63/65] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b9d257..ec30c4d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // diff --git a/package.json b/package.json index c8ebc89..91123ce 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-ind": "^0.2.3", "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 39ef0d5d29e48f42e7d338a6ae6c4c09f55eceec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Aug 2026 03:08:58 +0000 Subject: [PATCH 64/65] Remove files --- index.d.ts | 213 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5060 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 2a3bcf5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; -import { ComplexLike } from '@stdlib/types/complex'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Values array. -*/ -type ValuesArray = Collection | AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* -* var x = new Int32Array( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0, 40.0, 5.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var Complex128Array = require( '@stdlib/array-complex128' ); -* -* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 1, 2 ]; -* var values = new Complex128Array( [ 20.0, 30.0 ] ); -* -* var out = put( x, indices, values, 'throw' ); -* // returns -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: T, indices: IndexArray, values: ValuesArray, mode: Mode ): T; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Array, indices: IndexArray, values: ValuesArray, mode: Mode ): Array; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: AccessorArrayLike, indices: IndexArray, values: ValuesArray, mode: Mode ): AccessorArrayLike; - -/** -* Replaces specified elements of an array with provided values. -* -* @param x - input array -* @param indices - list of element indices -* @param values - values to set -* @param mode - index mode -* @returns input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var out = put( x, [ 1, 2 ], [ 30 ], 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -declare function put( x: Collection, indices: IndexArray, values: ValuesArray, mode: Mode ): Collection; - - -// EXPORTS // - -export = put; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a7248d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a47c659..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 76f93bdc9472a1544cb5c2a99b77d142737b4e0f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Aug 2026 03:09:16 +0000 Subject: [PATCH 65/65] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 165 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 79 - benchmark/benchmark.length.js | 114 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 6 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 91 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 48 - lib/main.js | 319 -- package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 528 -- 45 files changed, 4868 insertions(+), 5061 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.length.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1074032..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-19T03:07:17.124Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6893823..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/array/base/put) 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 06510ea..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/array/base/put) 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 59db94b..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: '44 20 * * 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -171,7 +162,7 @@ console.log( out ); ## 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]. @@ -234,9 +225,9 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-put/main/LICENSE -[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind +[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind/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 085038b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isArray = require( '@stdlib/assert-is-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::no_broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, x, 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::broadcasting:len=100', pkg ), function benchmark( b ) { - var idx; - var x; - var i; - var v; - - x = zeroTo( 100 ); - idx = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, [ i ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.js b/benchmark/benchmark.length.js deleted file mode 100644 index 3ee8520..0000000 --- a/benchmark/benchmark.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var put = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var idx; - var x; - - x = discreteUniform( len, 0, 10, opts ); - idx = zeroTo( len ); - values = [ - discreteUniform( len, -10, 0, opts ), - discreteUniform( len, 0, 10, opts ) - ]; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = put( x, idx, values[ i%values.length ], 'throw' ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1838cdf..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/array/base/put" -%% click B href "https://github.com/stdlib-js/array-base-put/tree/main" -%% click C href "https://github.com/stdlib-js/array-base-put/tree/production" -%% click D href "https://github.com/stdlib-js/array-base-put/tree/esm" -%% click E href "https://github.com/stdlib-js/array-base-put/tree/deno" -%% click F href "https://github.com/stdlib-js/array-base-put/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/put -[production-url]: https://github.com/stdlib-js/array-base-put/tree/production -[deno-url]: https://github.com/stdlib-js/array-base-put/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-base-put/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-base-put/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-base-put/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-base-put/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-base-put/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 34982e0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import put from '../docs/types/index'; -export = put; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 699c595..0000000 --- a/dist/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict";var w=function(r,a){return function(){try{return a||r((a={exports:{}}).exports,a),a.exports}catch(v){throw (a=0, v)}};};var j=w(function(z,b){ -var p=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/array-base-assert-is-boolean-data-type/dist'),f=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist'),q=require('@stdlib/strided-base-reinterpret-boolean/dist'),D=require('@stdlib/ndarray-base-ind/dist').factory,P=require('@stdlib/error-tools-fmtprodmsg/dist');function T(r,a,v,u,s,i){var e,t,o;for(e=0,t=0;t0)if(v.length===a.length)i=1;else if(v.length===1)i=0;else throw new Error(P('1wJFw',v.length,a.length));return s=D(u),e=r.length-1,t=f(r),o=f(a),n=f(v),t.accessorProtocol||o.accessorProtocol||n.accessorProtocol?p(t.dtype)&&p(n.dtype)?(B(y(r,0),o,y(v,0),i,s,e),r):m(t.dtype)&&m(n.dtype)?(C(q(r,0),o,q(v,0),i,s,e),r):(k(t,o,n,i,s,e),r):(T(r,a,v,i,s,e),r)}b.exports=A -});var E=j();module.exports=E; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 87297b5..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar ind = require( '@stdlib/ndarray-base-ind' ).factory;\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Replaces elements in an indexed array with provided values.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = [ 5, 6, 7, 8 ];\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = indexed( x, indices, values, 1, getIndex, x.length-1 );\n* // returns [ 8, 6, 7, 5 ]\n*/\nfunction indexed( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tiv = 0;\n\tfor ( i = 0; i < indices.length; i++ ) {\n\t\tj = getIndex( indices[ i ], maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces specified elements of an accessor array with provided values.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} indices - index object\n* @param {Object} values - values object\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var indices = toAccessorArray( [ 1, 2 ] );\n* var values = toAccessorArray( [ 20, 30 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 );\n*\n* var v = x.get( 0 );\n* // returns 1\n*\n* v = x.get( 1 );\n* // returns 20\n*/\nfunction accessors( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar xdata;\n\tvar idata;\n\tvar vdata;\n\tvar xset;\n\tvar iget;\n\tvar vget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\txdata = x.data;\n\tidata = indices.data;\n\tvdata = values.data;\n\n\txset = x.accessors[ 1 ];\n\tiget = indices.accessors[ 0 ];\n\tvget = values.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\txset( xdata, j, vget( vdata, iv ) );\n\t\tiv += stride;\n\t}\n\treturn xdata;\n}\n\n/**\n* Replaces elements in a complex array with provided values.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} indices - index array object\n* @param {Collection} values - real-valued floating-point values array view\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Collection} input array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n*\n* var indices = [ 0, 2 ];\n* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ind = require( '@stdlib/ndarray-base-ind' ).factory;\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = put;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Replace specified elements of an array with provided values.\n*\n* @module @stdlib/array-base-put\n*\n* @example\n* var put = require( '@stdlib/array-base-put' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAmB,QAAS,qCAAsC,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAM,QAAS,0BAA2B,EAAE,QAC5CC,EAAS,QAAS,uBAAwB,EA8B9C,SAASC,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIC,EACAC,EACAC,EAGJ,IADAF,EAAK,EACCC,EAAI,EAAGA,EAAIN,EAAQ,OAAQM,IAChCC,EAAIJ,EAAUH,EAASM,CAAE,EAAGF,CAAS,EACrCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAkCA,SAASS,EAAWT,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CACpE,IAAIK,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EACAC,EACAC,EAWJ,IATAE,EAAQV,EAAE,KACVW,EAAQV,EAAQ,KAChBW,EAAQV,EAAO,KAEfW,EAAOb,EAAE,UAAW,CAAE,EACtBc,EAAOb,EAAQ,UAAW,CAAE,EAC5Bc,EAAOb,EAAO,UAAW,CAAE,EAE3BI,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCQ,EAAMH,EAAOF,EAAGO,EAAMH,EAAON,CAAG,CAAE,EAClCA,GAAMH,EAEP,OAAOO,CACR,CA6BA,SAASM,EAAShB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAW,EACAV,EACAC,EACAU,EAOJ,IALAP,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BgB,EAAKd,EAAS,EACdG,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCa,EAAIV,EAAI,EACRR,EAAGkB,CAAE,EAAIhB,EAAQI,CAAG,EACpBN,EAAGkB,EAAE,CAAE,EAAIhB,EAAQI,EAAG,CAAE,EACxBA,GAAMW,EAEP,OAAOjB,CACR,CA6BA,SAASmB,EAASnB,EAAGC,EAASC,EAAQC,EAAQC,EAAUC,EAAW,CAClE,IAAIM,EACAG,EACAR,EACAC,EACAC,EAMJ,IAJAG,EAAQV,EAAQ,KAChBa,EAAOb,EAAQ,UAAW,CAAE,EAE5BK,EAAK,EACCC,EAAI,EAAGA,EAAII,EAAM,OAAQJ,IAC9BC,EAAIJ,EAAUU,EAAMH,EAAOJ,CAAE,EAAGF,CAAS,EACzCL,EAAGQ,CAAE,EAAIN,EAAQI,CAAG,EACpBA,GAAMH,EAEP,OAAOH,CACR,CAuCA,SAASoB,EAAKpB,EAAGC,EAASC,EAAQmB,EAAO,CACxC,IAAIjB,EACAD,EACAmB,EACAC,EACAC,EACAC,EAGJ,GAAKxB,EAAQ,OAAS,EAErB,GAAKC,EAAO,SAAWD,EAAQ,OAC9BE,EAAS,UACED,EAAO,SAAW,EAC7BC,EAAS,MAET,OAAM,IAAI,MAAOL,EAAQ,sIAAuII,EAAO,OAAQD,EAAQ,MAAO,CAAE,EAYlM,OARAG,EAAWP,EAAKwB,CAAK,EAGrBC,EAAMtB,EAAE,OAAS,EAEjBuB,EAAK7B,EAAkBM,CAAE,EACzBwB,EAAK9B,EAAkBO,CAAQ,EAC/BwB,EAAK/B,EAAkBQ,CAAO,EAE7BqB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAGEjC,EAAmB+B,EAAG,KAAM,GAAK/B,EAAmBiC,EAAG,KAAM,GACjET,EAASrB,EAAoBK,EAAG,CAAE,EAAGwB,EAAI7B,EAAoBO,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,GAEHP,EAAmB8B,EAAG,KAAM,GAAK9B,EAAmBgC,EAAG,KAAM,GACjEN,EAASvB,EAAoBI,EAAG,CAAE,EAAGwB,EAAI5B,EAAoBM,EAAQ,CAAE,EAAGC,EAAQC,EAAUkB,CAAI,EACzFtB,IAERS,EAAWc,EAAIC,EAAIC,EAAItB,EAAQC,EAAUkB,CAAI,EACtCtB,IAERD,EAASC,EAAGC,EAASC,EAAQC,EAAQC,EAAUkB,CAAI,EAC5CtB,EACR,CAKAT,EAAO,QAAU6B,ICpRjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isComplexDataType", "isBooleanDataType", "arraylike2object", "reinterpretComplex", "reinterpretBoolean", "ind", "format", "indexed", "x", "indices", "values", "stride", "getIndex", "maxIndex", "iv", "i", "j", "accessors", "xdata", "idata", "vdata", "xset", "iget", "vget", "complex", "sv", "k", "boolean", "put", "mode", "max", "xo", "io", "vo", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2cebb7d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( x, indices, values, mode ) - Replaces specified elements of an array with provided values. - - The function supports broadcasting a `values` array containing a single - element against an `indices` array containing one or more elements. - - The function mutates the input array. - - Because each index is only validated at the time of replacing a particular - element, mutation may occur even when one or more indices are out-of-bounds, - including when the index mode indicates to raise an exception. - - If `indices` is an empty array, the function returns the input array - unchanged. - - Parameters - ---------- - x: ArrayLikeObject - Input array. - - indices: ArrayLikeObject - List of element indices. - - values: ArrayLikeObject - Values to set. When `indices` contains one or more elements, `values` - must be broadcast compatible with `indices` (i.e., must have either one - element or the same number of elements as `indices`). - - mode: string - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. - - Returns - ------- - out: ArrayLikeObject - Input array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var out = {{alias}}( x, [ 1, 3 ], [ 20, 40 ], 'throw' ) - [ 1, 20, 3, 40 ] - > var bool = ( out === x ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 66cd3f9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( '@stdlib/array-complex128' ); -import Complex64Array = require( '@stdlib/array-complex64' ); -import Complex128 = require( '@stdlib/complex-float64-ctor' ); -import AccessorArray = require( '@stdlib/array-base-accessor' ); -import put = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType number[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 20, 30 ], 'clamp' ); // $ExpectType number[] - put( [ '1', '2', '3', '4' ], [ 1, 3 ], [ 20, 30 ], 'wrap' ); // $ExpectType (string | number)[] - put( [ 1, 2, 3, 4 ], [ 1, 3 ], [ true, true ], 'normalize' ); // $ExpectType (number | boolean)[] - - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectType Int32Array - put( new Complex128Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex128Array - put( new Complex64Array( [ 1, 2, 3, 4 ] ), [ 1, 3 ], [ new Complex128( 20, 30 ), [ 40, 50 ] ], 'throw' ); // $ExpectType Complex64Array - put( new AccessorArray( [ 1, 2, 3, 4 ] ), [ 1, 3 ], new AccessorArray( [ 20, 30 ] ), 'throw' ); // $ExpectType AccessorArrayLike -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - put( 1, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( true, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( false, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( null, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( void 0, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError - put( {}, [ 1, 3 ], [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - put( [], 1, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], true, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], false, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], null, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], void 0, [ 20, 30 ], 'throw' ); // $ExpectError - put( [], {}, [ 20, 30 ], 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object... -{ - put( [], [ 1, 3 ], 1, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], true, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], false, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], null, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], void 0, 'throw' ); // $ExpectError - put( [], [ 1, 3 ], {}, 'throw' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid index mode... -{ - put( [], [ 1, 3 ], [ 20, 30 ], '1' ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], 1 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], true ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], false ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], null ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], void 0 ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], {} ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], [] ); // $ExpectError - put( [], [ 1, 3 ], [ 20, 30 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - put(); // $ExpectError - put( [] ); // $ExpectError - put( [], [] ); // $ExpectError - put( [], [], [] ); // $ExpectError - put( [], [], [], 'throw', {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e0f2938..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var filledBy = require( '@stdlib/array-base-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var linspace = require( '@stdlib/array-base-linspace' ); -var put = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var N = discreteUniform( 5, 15 ); -var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); -console.log( indices ); - -// Generate an array of random values: -var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) ); -console.log( values ); - -// Update a random sample of elements in `x`: -var out = put( x, indices, values, 'throw' ); -console.log( out ); 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 3eae96a..2a3bcf5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, AccessorArrayLike, TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a7248d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex@v0.1.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.3-esm/index.mjs";import{factory as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function d(d,i,l,c){var m,h,p,g,f,j;if(i.length>0)if(l.length===i.length)h=1;else{if(1!==l.length)throw new Error(n("invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).",l.length,i.length));h=0}return m=o(c),p=d.length-1,g=s(d),f=s(i),j=s(l),g.accessorProtocol||f.accessorProtocol||j.accessorProtocol?e(g.dtype)&&e(j.dtype)?(function(e,t,s,r,a,o){var n,d,i,l,c,m;for(n=t.data,d=t.accessors[0],l=2*r,i=0,c=0;c[ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ]\n*/\nfunction complex( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar sv;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tsv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tk = j * 2;\n\t\tx[ k ] = values[ iv ];\n\t\tx[ k+1 ] = values[ iv+1 ];\n\t\tiv += sv;\n\t}\n\treturn x;\n}\n\n/**\n* Replaces elements in a boolean array with provided values.\n*\n* @private\n* @param {Uint8Array} x - input array\n* @param {Object} indices - index array object\n* @param {Uint8Array} values - values to set\n* @param {NonNegativeInteger} stride - index stride for accessing elements in `values`\n* @param {Function} getIndex - function for resolving an array index\n* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive)\n* @returns {Uint8Array} input array\n*\n* @example\n* import arraylike2object from '@stdlib/array-base-arraylike2object';\n* import Uint8Array from '@stdlib/array-uint8';\n* import { factory as ind } from '@stdlib/ndarray-base-ind';\n*\n* var x = new Uint8Array( [ 1, 0, 0, 1 ] );\n*\n* var indices = [ 3, 1, 2, 0 ];\n* var values = new Uint8Array( [ 0, 1, 1, 0 ] );\n*\n* var getIndex = ind( 'throw' );\n*\n* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 );\n* // returns [ 0, 1, 1, 0 ]\n*/\nfunction boolean( x, indices, values, stride, getIndex, maxIndex ) {\n\tvar idata;\n\tvar iget;\n\tvar iv;\n\tvar i;\n\tvar j;\n\n\tidata = indices.data;\n\tiget = indices.accessors[ 0 ];\n\n\tiv = 0;\n\tfor ( i = 0; i < idata.length; i++ ) {\n\t\tj = getIndex( iget( idata, i ), maxIndex );\n\t\tx[ j ] = values[ iv ];\n\t\tiv += stride;\n\t}\n\treturn x;\n}\n\n\n// MAIN //\n\n/**\n* Replaces specified elements of an array with provided values.\n*\n* @param {Collection} x - input array\n* @param {IntegerArray} indices - list of indices\n* @param {Collection} values - values to set\n* @param {string} mode - index mode\n* @throws {Error} third argument must be broadcast compatible with the second argument\n* @returns {Collection} input array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 20, 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 20, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var indices = [ 1, 2 ];\n* var values = [ 30 ];\n*\n* var out = put( x, indices, values, 'throw' );\n* // returns [ 1, 30, 30, 4 ]\n*\n* var bool = ( out === x );\n* // returns true\n*/\nfunction put( x, indices, values, mode ) {\n\tvar getIndex;\n\tvar stride;\n\tvar max;\n\tvar xo;\n\tvar io;\n\tvar vo;\n\n\t// Broadcast the `values` array...\n\tif ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements\n\t\t// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...\n\t\tif ( values.length === indices.length ) {\n\t\t\tstride = 1;\n\t\t} else if ( values.length === 1 ) {\n\t\t\tstride = 0;\n\t\t} else {\n\t\t\tthrow new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) );\n\t\t}\n\t}\n\t// Resolve a function for returning an index according to the specified index mode:\n\tgetIndex = ind( mode );\n\n\t// Resolve the maximum index:\n\tmax = x.length - 1;\n\n\txo = arraylike2object( x );\n\tio = arraylike2object( indices );\n\tvo = arraylike2object( values );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tio.accessorProtocol ||\n\t\tvo.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) {\n\t\t\tcomplex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\tif ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) {\n\t\t\tboolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len\n\t\t\treturn x;\n\t\t}\n\t\taccessors( xo, io, vo, stride, getIndex, max );\n\t\treturn x;\n\t}\n\tindexed( x, indices, values, stride, getIndex, max );\n\treturn x;\n}\n\n\n// EXPORTS //\n\nexport default put;\n"],"names":["put","x","indices","values","mode","getIndex","stride","max","xo","io","vo","length","Error","format","ind","arraylike2object","accessorProtocol","isComplexDataType","dtype","maxIndex","idata","iget","iv","sv","i","k","data","accessors","complex","reinterpretComplex","isBooleanDataType","boolean","reinterpretBoolean","xdata","vdata","xset","vget","indexed"],"mappings":";;ovBA0QA,SAASA,EAAKC,EAAGC,EAASC,EAAQC,GACjC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKR,EAAQS,OAAS,EAErB,GAAKR,EAAOQ,SAAWT,EAAQS,OAC9BL,EAAS,MACH,IAAuB,IAAlBH,EAAOQ,OAGlB,MAAM,IAAIC,MAAOC,EAAQ,sIAAuIV,EAAOQ,OAAQT,EAAQS,SAFvLL,EAAS,CAGT,CAWF,OARAD,EAAWS,EAAKV,GAGhBG,EAAMN,EAAEU,OAAS,EAEjBH,EAAKO,EAAkBd,GACvBQ,EAAKM,EAAkBb,GACvBQ,EAAKK,EAAkBZ,GAEtBK,EAAGQ,kBACHP,EAAGO,kBACHN,EAAGM,iBAGEC,EAAmBT,EAAGU,QAAWD,EAAmBP,EAAGQ,QA7I9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EAOJ,IALAL,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BJ,EAAc,EAATjB,EACLgB,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAG9BvB,EADAwB,EAAQ,EADJpB,EAAUgB,EAAMD,EAAOI,GAAKL,IAEvBhB,EAAQmB,GACjBrB,EAAGwB,EAAE,GAAMtB,EAAQmB,EAAG,GACtBA,GAAMC,CAGR,CAwHGK,CAASC,EAAoB5B,EAAG,GAAKQ,EAAIoB,EAAoB1B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,GAEH6B,EAAmBtB,EAAGU,QAAWY,EAAmBpB,EAAGQ,QA9F9D,SAAkBjB,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIC,EACAC,EACAC,EACAE,EAOJ,IAJAJ,EAAQlB,EAAQwB,KAChBL,EAAOnB,EAAQyB,UAAW,GAE1BL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BvB,EADII,EAAUgB,EAAMD,EAAOI,GAAKL,IACvBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CA8EGyB,CAASC,EAAoB/B,EAAG,GAAKQ,EAAIuB,EAAoB7B,EAAQ,GAAKG,EAAQD,EAAUE,GACrFN,IA1MV,SAAoBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACzD,IAAIc,EACAb,EACAc,EACAC,EACAd,EACAe,EACAd,EACAE,EAYJ,IATAS,EAAQhC,EAAEyB,KACVN,EAAQlB,EAAQwB,KAChBQ,EAAQ/B,EAAOuB,KAEfS,EAAOlC,EAAE0B,UAAW,GACpBN,EAAOnB,EAAQyB,UAAW,GAC1BS,EAAOjC,EAAOwB,UAAW,GAEzBL,EAAK,EACCE,EAAI,EAAGA,EAAIJ,EAAMT,OAAQa,IAE9BW,EAAMF,EADF5B,EAAUgB,EAAMD,EAAOI,GAAKL,GAChBiB,EAAMF,EAAOZ,IAC7BA,GAAMhB,CAGR,CAkLEqB,CAAWnB,EAAIC,EAAIC,EAAIJ,EAAQD,EAAUE,GAClCN,IA3PT,SAAkBA,EAAGC,EAASC,EAAQG,EAAQD,EAAUc,GACvD,IAAIG,EACAE,EAIJ,IADAF,EAAK,EACCE,EAAI,EAAGA,EAAItB,EAAQS,OAAQa,IAEhCvB,EADII,EAAUH,EAASsB,GAAKL,IACnBhB,EAAQmB,GACjBA,GAAMhB,CAGR,CAiPC+B,CAASpC,EAAGC,EAASC,EAAQG,EAAQD,EAAUE,GACxCN,EACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 78f8c2a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace specified elements of an array with provided values. -* -* @module @stdlib/array-base-put -* -* @example -* var put = require( '@stdlib/array-base-put' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ - -// 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 ec30c4d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,319 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var reinterpretComplex = require( '@stdlib/strided-base-reinterpret-complex' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var ind = require( '@stdlib/ndarray-base-ind' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Replaces elements in an indexed array with provided values. -* -* @private -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = [ 5, 6, 7, 8 ]; -* -* var getIndex = ind( 'throw' ); -* -* var out = indexed( x, indices, values, 1, getIndex, x.length-1 ); -* // returns [ 8, 6, 7, 5 ] -*/ -function indexed( x, indices, values, stride, getIndex, maxIndex ) { - var iv; - var i; - var j; - - iv = 0; - for ( i = 0; i < indices.length; i++ ) { - j = getIndex( indices[ i ], maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - -/** -* Replaces specified elements of an accessor array with provided values. -* -* @private -* @param {Object} x - input array object -* @param {Object} indices - index object -* @param {Object} values - values object -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array -* -* @example -* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); -* -* var indices = toAccessorArray( [ 1, 2 ] ); -* var values = toAccessorArray( [ 20, 30 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = accessors( arraylike2object( x ), arraylike2object( indices ), arraylike2object( values ), 1, getIndex, x.length-1 ); -* -* var v = x.get( 0 ); -* // returns 1 -* -* v = x.get( 1 ); -* // returns 20 -*/ -function accessors( x, indices, values, stride, getIndex, maxIndex ) { - var xdata; - var idata; - var vdata; - var xset; - var iget; - var vget; - var iv; - var i; - var j; - - xdata = x.data; - idata = indices.data; - vdata = values.data; - - xset = x.accessors[ 1 ]; - iget = indices.accessors[ 0 ]; - vget = values.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - xset( xdata, j, vget( vdata, iv ) ); - iv += stride; - } - return xdata; -} - -/** -* Replaces elements in a complex array with provided values. -* -* @private -* @param {Collection} x - real-valued floating-point input array view -* @param {Object} indices - index array object -* @param {Collection} values - real-valued floating-point values array view -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Collection} input array view -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* -* var indices = [ 0, 2 ]; -* var values = new Float64Array( [ 10.0, 20.0, 50.0, 60.0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = complex( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 10.0, 20.0, 3.0, 4.0, 50.0, 60.0, 7.0, 8.0 ] -*/ -function complex( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var sv; - var i; - var j; - var k; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - sv = stride * 2; // note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - k = j * 2; - x[ k ] = values[ iv ]; - x[ k+1 ] = values[ iv+1 ]; - iv += sv; - } - return x; -} - -/** -* Replaces elements in a boolean array with provided values. -* -* @private -* @param {Uint8Array} x - input array -* @param {Object} indices - index array object -* @param {Uint8Array} values - values to set -* @param {NonNegativeInteger} stride - index stride for accessing elements in `values` -* @param {Function} getIndex - function for resolving an array index -* @param {NonNegativeInteger} maxIndex - maximum array index (inclusive) -* @returns {Uint8Array} input array -* -* @example -* var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var ind = require( '@stdlib/ndarray-base-ind' ).factory; -* -* var x = new Uint8Array( [ 1, 0, 0, 1 ] ); -* -* var indices = [ 3, 1, 2, 0 ]; -* var values = new Uint8Array( [ 0, 1, 1, 0 ] ); -* -* var getIndex = ind( 'throw' ); -* -* var out = boolean( x, arraylike2object( indices ), values, 1, getIndex, x.length-1 ); -* // returns [ 0, 1, 1, 0 ] -*/ -function boolean( x, indices, values, stride, getIndex, maxIndex ) { - var idata; - var iget; - var iv; - var i; - var j; - - idata = indices.data; - iget = indices.accessors[ 0 ]; - - iv = 0; - for ( i = 0; i < idata.length; i++ ) { - j = getIndex( iget( idata, i ), maxIndex ); - x[ j ] = values[ iv ]; - iv += stride; - } - return x; -} - - -// MAIN // - -/** -* Replaces specified elements of an array with provided values. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Collection} values - values to set -* @param {string} mode - index mode -* @throws {Error} third argument must be broadcast compatible with the second argument -* @returns {Collection} input array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 20, 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 20, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 1, 2 ]; -* var values = [ 30 ]; -* -* var out = put( x, indices, values, 'throw' ); -* // returns [ 1, 30, 30, 4 ] -* -* var bool = ( out === x ); -* // returns true -*/ -function put( x, indices, values, mode ) { - var getIndex; - var stride; - var max; - var xo; - var io; - var vo; - - // Broadcast the `values` array... - if ( indices.length > 0 ) { // note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements - // Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation... - if ( values.length === indices.length ) { - stride = 1; - } else if ( values.length === 1 ) { - stride = 0; - } else { - throw new Error( format( 'invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).', values.length, indices.length ) ); - } - } - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = x.length - 1; - - xo = arraylike2object( x ); - io = arraylike2object( indices ); - vo = arraylike2object( values ); - if ( - xo.accessorProtocol || - io.accessorProtocol || - vo.accessorProtocol - ) { - // Note: we only explicitly support select dtype pairs, as this function should not be concerned with casting rules, etc. That is left to userland... - if ( isComplexDataType( xo.dtype ) && isComplexDataType( vo.dtype ) ) { - complex( reinterpretComplex( x, 0 ), io, reinterpretComplex( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - if ( isBooleanDataType( xo.dtype ) && isBooleanDataType( vo.dtype ) ) { - boolean( reinterpretBoolean( x, 0 ), io, reinterpretBoolean( values, 0 ), stride, getIndex, max ); // eslint-disable-line max-len - return x; - } - accessors( xo, io, vo, stride, getIndex, max ); - return x; - } - indexed( x, indices, values, stride, getIndex, max ); - return x; -} - - -// EXPORTS // - -module.exports = put; diff --git a/package.json b/package.json index 91123ce..e45a8fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.3", "description": "Replace specified elements of an array with provided values.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.2", - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex": "^0.1.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-linspace": "^0.2.3", - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-complex64": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float32-imag": "^0.1.2", - "@stdlib/complex-float32-real": "^0.1.2", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-array-discrete-uniform": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a47c659 --- /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 300ac27..0000000 --- a/test/test.js +++ /dev/null @@ -1,528 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isComplex64 = require( '@stdlib/assert-is-complex64' ); -var put = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof put, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (generic)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( [ 1, 2, 3, 4 ], [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (typed)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( new Int32Array( [ 1, 2, 3, 4 ] ), [ 1, 2 ], value, 'throw' ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not broadcast compatible with the second argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - [], - [ 1, 2, 3 ], - [ 1, 2, 3, 4 ], - [ 1, 2, 3, 4, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided an array of length ' + values[ i ].length ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - put( toAccessorArray( [ 1, 2, 3, 4 ] ), toAccessorArray( [ 1, 2 ] ), toAccessorArray( value ), 'throw' ); - }; - } -}); - -tape( 'the function replaces elements in an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = [ 1, 20, 3, 40 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 1, 30, 3, 50 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = [ 50, 40, 30, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (generic, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 1, 20, 3, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = [ 20, 20, 20, 20 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = [ 1, 100, 3, 4 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20, 40 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 40 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 1, 30, 3, 50 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20, 30, 40, 50 ], 'throw' ); - expected = new Int32Array( [ 50, 40, 30, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (typed, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 3, 3 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 1, 20, 3, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 3, 2, 1, 0 ]; - actual = put( x, indices, [ 20 ], 'throw' ); - expected = new Int32Array( [ 20, 20, 20, 20 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = put( x, indices, [ 100 ], 'throw' ); - expected = new Int32Array( [ 1, 100, 3, 4 ] ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 10.0, 20.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 50.0, 60.0 ), - new Complex64( 70.0, 80.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ - new Complex64( 100.0, 200.0 ) - ]; - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 30.0, 40.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 70.0, 80.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, complex, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new Complex64Array( [ 100.0, 200.0 ] ); - expected = [ - new Complex64( 1.0, 2.0 ), - new Complex64( 100.0, 200.0 ), - new Complex64( 5.0, 6.0 ), - new Complex64( 100.0, 200.0 ) - ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( isComplex64( v ), true, 'returns expected value' ); - t.strictEqual( realf( v ), realf( expected[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( v ), imagf( expected[ i ] ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = new BooleanArray( [ false, true, false, true ] ); - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function replaces elements in an array (accessors, boolean, broadcasting)', function test( t ) { - var expected; - var indices; - var actual; - var values; - var x; - var v; - var i; - - x = new BooleanArray( [ true, false, false, true ] ); - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - values = [ true ]; - expected = [ true, true, false, true ]; - actual = put( x, indices, values, 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - for ( i = 0; i < indices.length; i++ ) { - v = actual.get( i ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns the input array unchanged if provided a second argument which is empty', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - actual = put( x, [], [ 5, 6, 7, 8 ], 'throw' ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, [ 1, 2, 3, 4 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 200 ], 'throw' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = put( x, indices, [ 5, 6, 7, 8 ], 'normalize' ); - expected = [ 8, 7, 6, 5 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - put( x, indices, [ 100 ], 'normalize' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'clamp' ); - expected = [ 300, 2, 3, 400 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = put( x, indices, [ 100, 200, 300, 400 ], 'wrap' ); - expected = [ 1, 400, 200, 300 ]; - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -});